in Education by
I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using Django in 60 minutes and am stuck on page 6. So I have a Django project called blog and an inside I've an app called blogengine. Currently I am getting a TemplateDoesNotExist exception when I try loading 127.0.0.1:8000/blog/ Here is the full Traceback: Environment: Request Method: GET Request URL: http://127.0.0.1:8000/blog/ Django Version: 1.3.1 Python Version: 2.7.2 Installed Applications: ['blogengine', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware') Template Loader Error: Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: /home/sez/blog/templates/blogengine/post_list.html (File does not exist) Using loader django.template.loaders.app_directories.Loader: /usr/local/lib/python2.7/site-packages/django/contrib/admin/templates/blogengine/post_list.html (File does not exist) Traceback: File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python2.7/site-packages/django/views/generic/list_detail.py" in object_list 107. t = template_loader.get_template(template_name) File "/usr/local/lib/python2.7/site-packages/django/template/loader.py" in get_template 157. template, origin = find_template(template_name) File "/usr/local/lib/python2.7/site-packages/django/template/loader.py" in find_template 138. raise TemplateDoesNotExist(name) Exception Type: TemplateDoesNotExist at /blog/ Exception Value: blogengine/post_list.html In the Template Loader Error you can see Django tries to look for the post_list.html template in the /home/sez/blog/templates/blogengine/' directory. To get this working I have to make Django look in the/home/sez/blog/templates/blog/' directory but I still do not fully understand how URLconf works. Below are my 2 url.py files. The first is my project level url.py from django.conf.urls.defaults import patterns, include, url from django.views.generic.simple import direct_to_template from blog.views import * from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), (r'^static/(.*)$', 'django.views.static.serve', {'document_root': '/home/siddhion/blog/static/'}), (r'^(?P\w+)$', direct_to_template), (r'^$', static_page, {'template':'base'}), (r'^blog/', include('blog.blogengine.urls')), url(r'^(?P\w+)/$', static_page, name='static_page'), ) As I understand it, the line (r'^blog/', include('blog.blogengine.urls')), is telling redirecting control over to the url.py file in my blogengine directory. Here is the code for that file from django.conf.urls.defaults import * from django.views.generic import list_detail from blog.blogengine.views import Post urlpatterns = patterns('', url(r'^$', list_detail.object_list, { 'queryset': Post.objects.all(), 'template_object_name':'post', }, name='blog_home' ), ) So how what edits would I have to make to my urls.py files in order to get Django to find and render the post_list.html template? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Assuming that the file /home/sez/blog/templates/blog/post_list.html exists, you only have to tell Django where to look for it. Apparently, it looks for your templates in /home/sez/blog/templates/blogengine/. You can change that by adjusting TEMPLATE_DIRS in your settings.py: TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. '/home/sez/blog/templates/blog', ) However, it is common practice to name the template subdirectories as their corresponding apps, so you might want to consider moving your templates to blogengine, where Django assumes they are at the moment.

Related questions

0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I'm trying to follow PEP 328, with the following directory structure: pkg/ __init__.py components/ Core.py __init__ ... m missing here? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    I've been trying to get my discord bot to work, but it will only become online on discord and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm running Django 1.0 and I'm close to deploying my app. As such, I'll be changing the DEBUG ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    I have a very long forms.py and I'd like to split it to smaller parts with as few as possible ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    I'm trying to embed python into a C application. For the moment, I am trying to get the following ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I have created a partial view, the element in the partial view looks like this (Razor Code): @Html ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    I have created a partial view, the element in the partial view looks like this (Razor Code): @Html ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    This question's answers are a community effort. Edit existing answers to improve this post. It is not ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm trying to do a SQL Server 2008 setup and I've been given a Cross Language Installation failure ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm trying to do a SQL Server 2008 setup and I've been given a Cross Language Installation failure ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Explain how you can be stop your website getting hacked?...
asked Feb 20, 2021 by JackTerrance
...