Reputation: 153
I know this is a very noob question but need help with this when I try to render my product template it returns with this error , the first two pages were rendered correctly such as about , home and contact but when I tried to add another app for my products page it wouldnt load.
#THE ERROR
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/%7B%25%20url%20'products'%7D
Using the URLconf defined in trydjango.urls, Django tried these URL
patterns, in this order:
1. ^admin/
2. ^$ [name='home']
3. ^about/$ [name='about']
4. ^products/$ [name='products']
5. ^contact/$ [name='contact']
6. ^accounts/
7.^static\/(?P<path>.*)$
8.^static\/(?P<path>.*)$
The current URL, {% url 'products'}, did not match any of these.
#This is the structure
src
>> contact
>> products
>> migrations
>> templates
>> products.html
>> profiles
>> migrations
>> templates
>> about.html
>> base.html
>> home.html
>> navbar.html
#from the products app this is the views.py
def products(request):
context = {}
template = 'products.html'
return render(request, template,context)
#This is the config for urls
from profiles import views as profiles_views
from contact import views as contact_views
from products import views as products_views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', profiles_views.home, name='home'),
url(r'^about/$', profiles_views.about, name='about'),
url(r'^products/$', products_views.products, name='products'),
url(r'^contact/$', contact_views.contact, name='contact'),
url(r'^accounts/', include('allauth.urls')),
]
#and this is where I called it in navbar
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="{%url'products'}">Products</a>
</li>
Upvotes: 2
Views: 488
Reputation: 106
You also appear to me missing the closing '%' on the link template tag. It should be
<a class="nav-link js-scroll-trigger" href="{% url 'products' %}">Products</a>
Upvotes: 1
Reputation: 4213
Don't name the urls if it have a include, to do that go to the urls and add:
app_name='products'
urlpatterns = [
url(r'^$', your_view.path, name='home'),
]
and the refer it to:
{% url 'products:home' %}
Upvotes: 2