I've encountered an issue in my Django project when trying to submit a form. Can someone help me identify and fix the error?

Oops! An Error Occurred

We couldn't find the page you're looking for (Error 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.

**Here's the 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="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d232c20280d28352c203d2128632e2220">[email protected]</a>">
            </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")),
]

Answer №1

You might want to consider changing the URL to: http://localhost:8000/contact/

Therefore, update it to an empty value in order to switch from the current GET request to a POST request of the existing URL: action=""

It would probably be more appropriate to use action="{% url 'contact' %}" which refers to your named route contact.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Displaying outcomes in dialog box when button is pressed

I am working on a website where I want to enhance the user experience by displaying output in a dialogue box upon click. The current setup involves the user selecting a vendor and time duration, with the results appearing below the Submit button. However, ...

What is the best way to open a browser window at a quarter of its default size?

Is there a way to open a window at 25% of its default device browser window size? I attempted the code below, which worked. However, it only accepts pixel inputs and not relative % values. This makes it non-scalable across various devices. window.resizeT ...

How can I access the .ts variable value within an *ngIf statement in HTML?

My goal is to showcase images every 2 seconds, but currently I am only able to display all of them at once. Below is the HTML line I am using: <img id="bh" routerLink="/" *ngIf="bh?.id == count" [src]="bh?.src" height="42" width="42"/> Here is t ...

Two neighboring sections containing dynamic elements. One section automatically adjusts its size to fit the content, while the other allows

I need to display 2 adjacent boxes with dynamic content rendered using Angular. The Container should have the same height as Box1. The height of Box2 may vary due to its dynamic nature, but it should never be taller than Box1. If it does become higher, a s ...

Activate the input autofocus feature when displaying a dialog in Vue.js

When opening a dialog with input text using v-menu upon clicking a button, how can I focus on the input text field? I have attempted to use $ref but it does not seem to work. newFolderClick(){ this.$refs["input_new_folder"].focus(); //it still appea ...

Display resize grip when hovering

Is there a way to make elements resizable using resize: both, but only show the corner handle when hovering over the element? https://i.sstatic.net/cGIYf.png I am looking for a solution to display that specific handle only on hover. ...

.Net RadioButton object

Having trouble styling my radio button. When I compile and check the code with Firebug, something unusual happens. Code snippet: <asp:RadioButton ID="selType1" GroupName="Type" runat="server" CssClass="radioB" Checked="true" /> Firebug result: & ...

The hyperlink tag doesn't respond to clicks in Safari, yet functions properly in all other web browsers

I'm encountering an issue with my header drop-down menu in Safari—it works perfectly in Chrome, but when I try to open the drop-down menu in Safari, it's unresponsive. Clicking on it does nothing, preventing me from accessing other drop-downs. ...

The resizing effect in jQuery causes a blinking animation

I would like to create a functionality where, when the width of .tabla_gs_gm surpasses the width of .content, .tabla_gs_gm disappears and another div appears in its place. While this is already working, there seems to be a screen flicker between the two d ...

jQuery mCustomScrollbars does not correctly resize the height of the div on the initial load

Need help with resizing the height of a div. Currently, I am setting the height of the div using JavaScript, but it only takes effect after refreshing the page (F5). Is there a way to make it work without needing a refresh? Check out the code snippet be ...

Divide Footer Information into Two Sections: Left and Right

<footer> <div class="copyrights-left"> <p>&copy 2015. <a style="color: #fff;" href="index.html">Free Xbox Live Gold Membership and Free Xbox Live Gold Codes</a>. All rights reserved.</p></div> <div class="co ...

Utilizing the empty space to the right of an image in HTML

What could be causing the empty space to the right of my image? This is how the HTML file appears: ... <body> <div class="image"> <img src="image.jpg" alt="Picture here" id="image" align="middle"></img> </div> ...

javascript strange behavior

I am facing an issue with my code that is attempting to display images based on their height. Strangely, the code seems to work fine when I test it with 2 images, but fails when trying with 3 or more. Check out the site: Upon clicking a menu button, the ...

Updating input value using v-model in Vue.js does not reflect changes

I'm struggling with formatting numbers that I input in an HTML text box. I have a function that is supposed to format the number when I click out of the input box, but the updated value is not reflected in the v-model. The function is working correct ...

A method using CSS to automatically resize an image in a teaser box as text content increases, ensuring compatibility across various web

In the process of constructing a teaser element using HTML, I plan to integrate an image and a title. This is what I have in mind: <div> <img src="./image.jpg" /> <h1 contenteditable>Something</h1> </div> Wh ...

What are the steps for placing a watermark on a PDF document?

Is there a way to incorporate a watermark into a PDF file generated from the following code? import xhtml2pdf from xhtml2pdf import pisa def delivery_cancel(request, did): d_instance = get_object_or_404(Delivery, pk=did, user=request.user) users ...

The action does not execute when the form is submitted

I’m currently working on a simple registration form, but I’ve encountered an issue with my code. Despite troubleshooting, I can’t seem to identify any errors in my code. Upon submission of the form, the page fails to redirect to register.php. Below ...

Creating a function that generates a random number of <div> elements and places them inside a <li> element is a great way to dynamically add

Hey there! I could really use your assistance with this. I am trying to dynamically generate a list of items, but instead of placing each item in a separate <li>, I would like to achieve the following structure: <ul> <li> <di ...

Having difficulty accessing object property using Chunk Template Engine

I am working on a project where I have created a list of objects and now need to retrieve the object name from a template using the Chunk Template Engine. The object list has been initialized as follows: html.set("items", new Item[]{new Item("Item 1", 2) ...

Clearing Time Field Input in Safari

Recently, I've been utilizing the following HTML input element: <input type="time"> While testing it in both Chrome and Safari, I noticed that the clear field (cross button) is absent when using Safari. How can I make the cross button appear i ...