I am getting an error in django project while submitting the form can any one please tell the correction of my error

Viewed 28

Error

Page not found (404) Request Method: POST Request URL: http://localhost:8000/contact/contact Using the URLconf defined in portfolio.urls

admin/
[name='home']
about/ [name='about']
projects/ [name='projects']
contact/ [name='contact']
The current path, contact/contact, didn't match any of these.

**code for the form **

<form action="contact" method="POST">
            {% csrf_token %}
            <div class="form-group">
              <label for="name">Name</label>
              <input type="text" class="form-control" id="name"  name="name" placeholder="Your Name">
            </div>

            <div class="form-group">
              <label for="email">Email address</label>
              <input type="email" class="form-control" id="email" name="email" placeholder="name@example.com">
            </div>

            <div class="form-group">
              <label for="phone">Phone Number</label>
              <input type="phone" class="form-control" id="phone" name="phone" placeholder="Your Number">
            </div>

            <div class="form-group">
              <label for="exampleFormControlTextarea1">Explain your concern</label>
              <textarea class="form-control" id="desc" rows="3"></textarea>
            </div>

            <button type="submit" class="btn btn-success">Submit</button>
          </form>

views.py

def contact(request):
    return render(request,"contact.html")

urls.py this url is from my app

urlpatterns=[
    path("",views.home,name="home"),
    path("about/",views.about,name="about"),
    path("projects/",views.projects,name="projects"),
    path("contact/",views.contact,name="contact"),
]

urls.py this url is from my project

urlpatterns = [
    path('admin/', admin.site.urls),
    path("",include("home.urls")),
]
1 Answers

The url should propbaly be: http://localhost:8000/contact/

So change it to blank so will it from current which is a GET request to a POST request of the current url: action=""

Propably better to use action="{% url 'contact' %}" which is your named route contact.

Related