Home > front end >  How can i omit a url so i reach the url i want
How can i omit a url so i reach the url i want

Time:05-01

hi i have a Form an the action method is 'Home_Search' i want to reach the Home_Search view but when ever i Post something the url will be like this http://127.0.0.1:8000/home/Home_Search and Page not found error will be raised , is there any method so i can exclude /home from the url?Only for this Form...

my url.Py :

path("home/", views.home, name="home"),
path("Home_Search/", views.Home_Search, name="Home_Search"),

and my Form is : <form action="Home_Search" method="post" role="form">

CodePudding user response:

You can use an absolute url with a leading slash, so:

<form action="/Home_Search/" method="post" role="form">
    …
</form>

but it is better to work with the {% url … %} template tag [Django-doc] to determine the reverse URL:

<form action="{% url 'Home_Search' %}" method="post" role="form">
    …
</form>

URLs however often tend to have no uppercase characters. It thus might be better to rewrite the path to home-search/.

  • Related