2012-02-28 2 views
-3
class Entry(models.Model): 
    .... 
    slug = models.SlugField(help_text = "You do not need to change this unless you want to change the url") 

class Meta: 
    verbose_name_plural = "Entries" 

def __unicode__(self): 
    return self.title 

def get_absolute_url(self): 
    cat = slugify(self.category)  
    return "%s/%s/" % (cat,self.slug) 

전망

def index(request): 
    all_entries = Entry.objects.filter(status=1) 
    treatments = all_entries.filter(category='treatments') 
    female = all_entries.filter(category='female') 
    male = all_entries.filter(category='male') 
    work = all_entries.filter(category='work') 

    return render_to_response('index.html',locals()) 

def entry_page(request,slug_add): 
    all_entries = Entry.objects.filter(status=1) 
    page = all_entries.get(slug=slug_add) 

    treatments = all_entries.filter(category='treatments') 
    female = all_entries.filter(category='female') 
    male = all_entries.filter(category='male') 
    work = all_entries.filter(category='work') 
    return render_to_response('index.html',locals()) 

URL

url(r'^$','hypno_pages.views.index'), 
url(r'^admin/', include(admin.site.urls)), 
url(r'^$','hypno_pages.views.index'), 
url(r'^(treatments|male|female|work)/(?P<slug_add>[a-zA-Z0-9-]+)/$','hypno_pages.views.entry_page'), 

템플릿

<div class="subnav ui-corner-all"> 
    <h3>xxxxx can help to treat any of the following conditions </h3> 
<ul class = 'float' >  
     {% for line in treatments|slice:":5" %} 
     <li ><a href='{{line.get_absolute_url}}'>{{ line.title }}</a></li> 
    {% empty %} 

     {% endfor %} 
    </ul> 
    <ul class = 'float'> 
    {% for line in treatments|slice:"5:10" %} 
     <li ><a href="{{line.get_absolute_url }}" >{{ line.title }}</a></li> 
    {% empty %} 
    {% endfor %} 
</ul> 
    ....... 

* 편집 * 즉 템플릿 코드는 그냥 잘립니다 , 다른 부분은 방금 반복됩니다.장고 URL이 중복 유지 (동적 탐색)

내 문제. 많은 링크가있는 드롭 다운 상자가있는 기본 색인 페이지가 있습니다. 클라이언트가 무언가를 추가하면 데이터베이스에서 동적으로 추가됩니다. 내 문제는 탐색 링크에 있습니다. 'http://127.0.0.1:8000/treatments/what-to-do/'링크를 클릭하면 링크 된 페이지로 이동하지만 탐색 바의 모든 링크는 'http : //127.0'으로 변경됩니다. .0.1 : 8000/treatment/what-to-do/treat/what-to-do/'특정 링크에 대한 액세스 장고로 1 주일, 파이썬으로 한 달에 무언가를 놓친 것 같아요.

+0

그래서 어떤 코드가 문제를 일으키는 지 생각 하시나요? – Marcin

+0

@ephan - 생성되는 링크를 보여주는 템플릿 코드 부분을 게시하는 것이 좋습니다. –

+0

@DominicRodger 방금 템플릿 코드를 작성했습니다. – ephan

답변

0

내게있어, 당신이 "hrefs"에서 절대 경로 지정을 사용해야하는 것처럼 보입니다. 왜냐하면 당신이 그것을 사용하는 것처럼, 링크는 상대적이고 앱이 될 것이기 때문입니다

대신 <a href="/{{line.get_absolute_url }}" >을 시도 당신이 이미있는 (URL-) 경로로 끝났다.

또한 나는 당신의 get_absolute_url 함수의 @pemarlink 장식을 사용합니다. 보세요 here.

+0

덕분에 많이 도움이되지 않았고 지금은 며칠 동안 퍼머와 싸우고있다, 것을 시도 URL은 항상, 여전히 learning.For 지금 거 사용 장고 컨텍스트 기본적인 생각된다 blank.I 내 대부분의 문제를 알고 보여줍니다 -이 문제에 대한 프로세서. – ephan