Я делаю раздел "Свяжитесь с нами" на моем сайте.Когда я захожу в раздел контактов на моей веб-странице, он выглядит следующим образом: This
Я не уверен, связано ли это с моим URL, поскольку раздел контактов на странице отображается как http://127.0.0.1:8000/#contact-section
?
forms.py
from django import forms
class ContactForm(forms.Form):
name = forms.CharField(max_length=100)
email = forms.EmailField()
subject = forms.CharField(max_length=100)
message = forms.CharField(widget=forms.Textarea)
Views.py
from django.shortcuts import render
from django.views.generic import View
from django.http import HttpResponse
from contact.forms import ContactForm
def index_view(request):
return render(request, 'index.html', {})
def post_view(request):
return render(request, 'single.html', {})
def contact_us(request):
if request.method == 'POST':
form =ContactForm(request.POST)
if form.is_valid():
# Send email goes here
return HttpResponse("Thanks for contacting, We will be in touch soon!")
else:
form = ContactForm()
return render(request, 'index.html', {'form': form})
Шаблон
<div class="row no-gutters block-9">
<div class="col-md-6 order-md-last d-flex">
<form method="POST" action="." class="bg-light p-4 p-md-5 contact-form">
<div class="form-group">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Send Message" class="btn btn-primary py-3 px-5">
</div>
</form>
</div>