python - Django generate url in template -
i'm new django.
i have created pages
app hosts static files home
, about
, etc
in urls.py
of pages
app, have defined url access home
class on /pages
from django.conf.urls import url . import views app_name = 'pages' urlpatterns = [ url(r'^$', views.homeview.as_view(), name='home') ]
and included in myapp/urls.py
urlpatterns = [ url('^', include('pages.urls')), url(r'^pages/', include('pages.urls')), ]
i have included 2 patterns set url(r'^$', views.homeview.as_view(), name='home')
of pages
app access /
(root) , using pages/home
question: how generate url in template?
generating url in template pages
{% url 'home' %}
working fine , accessible using pages/home
but, have template file base.html
outside of apps serves basic structure app templates using {% extends 'base.html' %}
when generate url in base.html
{% url 'home' %}
gives error as
reverse 'home' not found. 'home' not valid view function or pattern name.
i tried {% url 'pages/home' %}
, {% url 'pages.home' %}
gives same error.
Comments
Post a Comment