I have a single flow Bootstrap template with all the sections like "About", "Contact" and others as part of a single file. The problem comes with the menu bar as I am using django's inheritance for templates to include the menu bar(declared in home_menubar.html) and I use the line {% include 'home/home_menubar.html' %}
in all my webpages for the menu bar.
The problem is I had to declare specific urls for all the categories in the menu bar so as to render the same HTML file for displaying a particular section in the page like if I want to visit the about column. the url would be localhost:8000/about/#aboutus
That URL looks is sickening me. Is there any way the URL would become localhost:8000/#aboutus
??
Update 1: I use the home_menubar.html
file in many webpages like login.html, register.html etc. So if I issued
localhost:8000/login/
and About menu item is clicked, it becomes localhost:8000/login/#about
which DOES NOT exist.
Some code:
home_menubar.html
{% load staticfiles %}
<nav class="navbar navbar-inverse navbar-fixed-top" style="font-family: 'Open Sans';">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="{% url 'web_root' %}" class="navbar-brand"><img src="{% static 'home/images/logo.png' %}" alt="company logo" /></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right custom-menu">
<li><a href="{% url 'about' %}">About</a></li>
<li><a href="{% url 'benefits' %}">Benefits</a></li>
{% ifnotequal events_obj None %}
<li><a href="{% url 'upevents' %}">Upcoming Events</a></li>
{%endifnotequal%}
<li><a href="{% url 'contactus' %}">Contact</a></li>
</ul>
</div>
</div>
</nav>
views.py:
def show_homepage(request):
return render(request,'home/homepage.html')
def view_about(request):
return render(request,'home/homepage.html',{'goto':'about'})
def view_benefits(request):
return render(request,'home/homepage.html',{'goto':'benefits'})
def view_upevents(request):
return render(request,'home/homepage.html',{'goto':'upevents'})
urls.py
url(r'^$', views.show_homepage,name="web_root"),
url(r'^benefits/', views.view_benefits,name="benefits"),
url(r'^upevents/', views.view_upevents,name="upevents"),
url(r'^about/', views.view_about,name="about"),
I don't understand why you're duplicating views at all...
Why not just have a single home page view:
def show_homepage(request):
return render(request, 'home/homepage.html')
With an accompanying URL:
url(r'^$', views.show_homepage, name="web_root"),
And then in home_menubar.html :
<ul class="nav navbar-nav navbar-right custom-menu">
<li><a href="/#about">About</a></li>
<li><a href="/#benefits">Benefits</a></li>
{% ifnotequal events_obj None %}
<li><a href="/#upevents">Upcoming Events</a></li>
{%endifnotequal%}
<li><a href="/#contactus">Contact</a></li>
</ul>
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.