我有Django的urls.py的正則表達式部分的問題。我想爲每個輸入的用戶顯示一個頁面。 我views.py看起來像:Django的網址正則表達式不工作
def tekent(request):
tumentry = Entry.objects.get(id=id)
return render_to_response("baslik/tekentry.html", locals(), context_instance=RequestContext(request))
def tek(request, slug):
basliklar = Baslik.objects.filter(active=True).order_by('-updated')
baslik = Baslik.objects.get(slug=slug)
entryler = baslik.entry_set.all()
form2 = EntryForm(request.POST or None)
if form2.is_valid():
entry = form2.save(commit=False)
entry.baslik = baslik
entry.user = request.user
entry.save()
return HttpResponseRedirect('/entry/%s'%(entry.id))
return render_to_response("baslik/tek.html", locals(), context_instance=RequestContext(request))
我主要urls.py(而不是應用程序的)看起來像這樣:
from baslik import *
urlpatterns = patterns('',
url(r'^entry/(?P<Entry.id>)/$', 'tekent', name = "tek_entry"),
)
,當我上添加Web瀏覽器的入口,它會引發錯誤像這樣:
DoesNotExist at /baslik/entry4/
Baslik matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/baslik/entry4/
Django Version: 1.6.5
Exception Type: DoesNotExist
Exception Value:
Baslik matching query does not exist.
Exception Location: /Users/malisit/Django/sozluk/lib/python2.7/site-packages/django/db/models/query.py in get, line 310
Python Executable: /Users/malisit/Django/sozluk/bin/python
我該怎麼辦才能解決這個問題?謝謝。
'R '^項/(ΔP)/ $''不一個有效的Python正則表達式。 –
Unihedron
我應該如何改變它以使其工作? – malisit