django url rule not working
I'm a django newbie. Here is my problem.... My main urls.py has a rule for checking pub开发者_JS百科lished section to published app, like this:
(r'^(published/)$', include('published.urls')),
My published app urls.py is like:
urlpatterns = patterns('published.views',
# Examples:
(r'^$', 'index',),
(r'^(?P<id>\d+)/$', 'article'),
)
I'm trying to fetch a url like this
http://localhost:8000/published/2/
Problem is its showing a 404 error. Just to clarify my view is like this:
def article(request):
try:
p = Published.objects.get(pk = id)
except Published.DoesNotExist:
raise Http404
return render_to_response('published/inner.html', {'pubs': p}, context_instance = RequestContext(request))
Can anyone tell me what is the problem?
You should try removing the $
from the end of r'^(published/)$'
. If it still does not work, try removing the ^
from the beginning of r'^(?P<id>\d+)/$'
. Since $
matches the end of a string, the regex fails to match when there is a character after the first /
.
精彩评论