Thursday, September 1, 2011

Re: Unable to have a template NOT show up

To be honest, I have no idea.  I was just following the tutorial (maybe I edited the wrong file, maybe the tutorial is wrong.)  Do you know of a good book on this subject that not only teaches you about Django, but also about frameworks?

This is the contents of one urls.py file (in a project called mysite):

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^polls/', include('polls.urls')),
    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)

And this is the contents of one of the urls.py file in the apps in the project.

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('polls.views',
    (r'^polls/$', 'index'),
    (r'^polls/(?P<poll_id>\d+)/$', 'detail'),
    (r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
    (r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
)

urlpatterns += patterns('',
    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)

My guess is that the when it first gets included, the ^polls gets prep-ended in the process.

Now, when I removed the ^polls/ in the project urls.py, I got this, which is something what I'd expect to get earlier... but then I thought that the template is there:

TemplateDoesNotExist at /polls/1/

 polls/detail.html
Request Method:GET
Request URL:http://localhost:8000/polls/1/
Django Version:1.3
Exception Type:TemplateDoesNotExist
Exception Value:
 polls/detail.html
Exception Location:C:\Python27\lib\site-packages\django\template\loader.py in find_template, line 138
Python Executable:C:\Python27\python.exe
Python Version:2.7.2
Python Path:
 ['C:\\Users\\ashvets\\Development\\Code\\mysite',  'C:\\Windows\\system32\\python27.zip',  'C:\\Python27\\DLLs',  'C:\\Python27\\lib',  'C:\\Python27\\lib\\plat-win',  'C:\\Python27\\lib\\lib-tk',  'C:\\Python27',  'C:\\Python27\\lib\\site-packages']
Server time:Thu, 1 Sep 2011 09:39:09 -0400

Template-loader postmortem

Django tried loading these templates, in this order:

  • Using loader django.template.loaders.filesystem.Loader:
    • c:\users\ashvets\my_templates\admin\base_site.html\polls\detail.html (File does not exist)
  • Using loader django.template.loaders.app_directories.Loader:
    • c:\python27\lib\site-packages\django\contrib\admin\templates\polls\detail.html (File does not exist)

On Thu, Sep 1, 2011 at 9:25 AM, Reinout van Rees <reinout@vanrees.org> wrote:
On 01-09-11 15:04, Yves S. Garret wrote:

Using the URLconf defined in |mysite.urls|, Django tried these URL
patterns, in this order:

 1. ^polls/ ^polls/$
 2. ^polls/ ^polls/(?P<poll_id>\d+)/$
 3. ^polls/ ^polls/(?P<poll_id>\d+)/results/$
 4. ^polls/ ^polls/(?P<poll_id>\d+)/vote/$
 5. ^polls/ ^admin/
 6. ^admin/


The current URL, |polls/1/|, didn't match any of these.

Such a "^polls/ ^polls/$" regex is incorrect. What's the extra
"^polls/ " doing in front of the actual regex? That's the cause of your error, I think.




Reinout

--
Reinout van Rees                    http://reinout.vanrees.org/
reinout@vanrees.org             http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment