URLs of pages done in admin panel

107 views
Skip to first unread message

Unkle UU

unread,
Mar 27, 2016, 12:21:51 PM3/27/16
to django-oscar
Hello everyone.

i'm trying to add some links in a navigation bar.
In dashboard->Content->Pages i can create pages and give then URL like '/contacts/' for example.
but it is not displayed in navbar of the page.
at the same moment url  like localhosl:8000/contacts/  - works

i decided simply add some links inside nav_extra tags in nav_primary.html

{% block nav_extra %}
              <li><a href="#">Home</a></li>
              <li><a href="#">About</a></li>
              <li><a href="#">Contact</a></li>
{% endblock %}

from that moment i'm trying to give not hardcoded url in href tag of the link.
link works only like <li><a href="/contacts/">Contact</a></li> 

what not hard coded url can be fill in???


Unkle UU

unread,
Mar 28, 2016, 4:36:03 AM3/28/16
to django-oscar
For everyone who is interested.

Everything you did in dashboard->Content->Page - are flatpages
to activate flat pages in your template you should insert in the top of your template 
{% load flatpages %}
{% get_flatpages as flatpages %}

So if you want for example additional link like this in the navigation bar

  




you have to insert in nav_primary.html

{% block nav_extra %}
         {% for page in flatpages %}
<li><a href="{{ page.url }}">{{ page.title }}</a></li>
 {% endfor %}
{% endblock %}

Good luck.

воскресенье, 27 марта 2016 г., 19:21:51 UTC+3 пользователь Unkle UU написал:

Juanjo A.

unread,
Nov 21, 2016, 8:16:37 AM11/21/16
to django-oscar
Good tip, thanks!

Juanjo A.

unread,
Nov 21, 2016, 8:33:31 AM11/21/16
to django-oscar
Note: You need url(r'', include('django.contrib.flatpages.urls')),  in your urls.py, on last line to no capture others url.
Reply all
Reply to author
Forward
0 new messages