简体   繁体   中英

Mapping template folder in Django

I am not able to map html files from the directory, however i've followed all the instructions.

Following is my project urls.py:-

 from django.conf.urls import patterns, include, url
      # Uncomment the next two lines to enable the admin:
      # from django.contrib import admin
      # admin.autodiscover()
      urlpatterns = patterns('',
           url(r'^articles/', include('article.urls')),
 )

Views.py in app:-

      from django.shortcuts import render_to_response
      from article.models import Article

        def articles(request):
             return render_to_response('articles.html',{'articles':                 
                       Article.objects.all()})
         def article(request, article_id=1):
             return render_to_response('article.html',{'article':            
                       Article.objects.get(id=article_id)})

Urls.py in app:

      from django.conf.urls import patterns, include, url
      urlpatterns = patterns('', 
        url(r'^all/$', 'artilce.views.articles'),
        url(r'^get/(?P<article_id>\d+)/$', 'article.view.article'),
  )

Settings.py shows exact location of template folder as:-

       TEMPLATE_DIRS = (
              'C:\Python27\Scripts\django_test\article\templates',

Kindly advise. It shows article on 404 page but couldn't map.

You need to use unix-style forward slashes for your path, even on Windows. See the doc page here: https://docs.djangoproject.com/en/1.6/ref/settings/#template-dirs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM