我在索引/主页中附加了一个联系页面。它没有任何contact.html页面。如何在导航栏中为联系人提供url,以使其向下滑动到同一主页中的联系人页面。
index.html
<div class="nav-container">
<ul>
<li><a href="{% url 'company:home' %}">Home</a></li>
<li><a href="{% url 'company:about' %}">About</a></li>
<li><a href="{% url 'company:services' %}">Services</a></li>
<li><a href="">Portfolio</a></li>
<li><a href="{% url 'company:blog' %}">Blog</a></li>
<li><a href="">Contact</a></li> # what url should i have to give here so that it gives the contact page within this index page
</ul>
</div>
<!-- Contact Section -->
<section id="contact">
<div class="container">
<h1 class="title">Contact Us
<p>HOW TO CONNECT WITH US ?</p>
<span class="underline"></span>
</h1>
<div class="row">
<div class="col-md-6">
<div class="map">
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d7066.152739935275!2d85.3461636!3d27.6840344!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x39eb19a18187378f%3A0x8ba2460dd7896e64!2sOnline+Zeal!5e0!3m2!1sen!2snp!4v1553841516009!5m2!1sen!2snp" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
</div>
</div>
<div class="col-md-6">
<form action="{% url 'company:contact' %}" method="post">
{% csrf_token %}
<label for="full-name">Full Name *</label>
<input id="name" type="text" name="full_name" class="form-control">
<label for="full-name">Email Address *</label>
<input id="full-name" type="email" name="email" class="form-control">
<label for="full-name">Comment (if any)</label>
<textarea name="comment" rows="3" class="form-control" ></textarea>
<button type="submit" class="btn btn-alternate">Submit</button>
</form>
</div>
</div>
</div>
</section>
views.py
def homepage(request):
services = Service.objects.filter(active=True)
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
contact = form.save(commit=False)
contact.save()
else:
messages.error(request,'Error in Form.')
else:
form = ContactForm()
return render(request,'company/index.html',{'services':services,'form':form})
forms.py
class ContactForm(forms.ModelForm):
class Meta:
model = Contact
fields = ['full_name','email','comment']
urls.py
path('',views.homepage,name='home'),
path('contact/',views.contact,name='contact'),
答案 0 :(得分:2)
在导航栏中使用href和哈希号:
def loopdir(dirs):
imgs=[]
dirs=[]
for dir in dirs:
for records in dir:
if record==img:
imgs.append(record)
else
dirs.append(record)
return (imgs,dirs)
dirs=['init']
images=[]
while dirs:
imgs,dirs=loopdirs(d)
images +=imgs
dirs+=dirs
然后联系自己,您将为其提供ID:
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#contact">contact</a>
</li>
您当然可以使用<div class="col-md-6" id="contact">
标记或您喜欢的任何标记,