[英]How to add parameters to the homepage URL in Django
I have a single flow Bootstrap template with all the sections like "About", "Contact" and others as part of a single file. 我有一个单一的流程Bootstrap模板,所有部分(如“关于”,“联系”和其他部分)都作为一个文件的一部分。 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. 问题出在菜单栏上,因为我正在使用django的模板继承来包含菜单栏(在home_menubar.html中声明),并且我在所有网页中都使用行{% include 'home/home_menubar.html' %}
菜单栏。
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. 问题是我必须在菜单栏中为所有类别声明特定的url,以便呈现相同的HTML文件以在页面中显示特定的部分,就像我要访问about列一样。 the url would be localhost:8000/about/#aboutus
网址为localhost:8000/about/#aboutus
That URL looks is sickening me. 该网址看起来让我感到恶心。 Is there any way the URL would become localhost:8000/#aboutus
?? URL有什么方法可以变成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 更新1:我在许多网页中使用home_menubar.html
文件,例如login.html,register.html等。因此,如果我发出
localhost:8000/login/
and About menu item is clicked, it becomes localhost:8000/login/#about
which DOES NOT exist.
,然后在该URL: localhost:8000/login/
中单击关于菜单项,它将变为localhost:8000/login/#about
,该菜单项不存在。
Some code: 一些代码:
home_menubar.html 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: 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 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:
url(r'^$', views.show_homepage, name="web_root"),
And then in home_menubar.html : 然后在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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.