I’m a django newbie. Here is my problem…. My main urls.py has a rule for checking published 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 ofr'^(published/)$'. If it still does not work, try removing the^from the beginning ofr'^(?P<id>\d+)/$'. Since$matches the end of a string, the regex fails to match when there is a character after the first/.