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 주일, 파이썬으로 한 달에 무언가를 놓친 것 같아요.
그래서 어떤 코드가 문제를 일으키는 지 생각 하시나요? – Marcin
@ephan - 생성되는 링크를 보여주는 템플릿 코드 부분을 게시하는 것이 좋습니다. –
@DominicRodger 방금 템플릿 코드를 작성했습니다. – ephan