urls.py configuration file for the project
- From message.views import GetForm
- Urlpatterns = [
- URL (r ' ^admin/', admin.site.urls),
- URL (r ' ^form/$ ', getform)
- ]
This is the original, in the HTML we introduced to:
<form action="/form/" method="post" class="smart-green">
The above writing is dead, but if we want to modify the URL later, we need each HTML file to change the URL is more troublesome, so we have to configure the URL alias
- From message.views import getform
- Urlpatterns = [
- URL (R ' ^admin/', admin.site.urls),
- URL (R ' ^form/$ ', getform,name=' go_form ')
- ]
We have already written the alias of the form as go_form, so we can match the URL directly with the {% url ' go_form '%} in the HTML, so the benefit is that we can arbitrarily correct the form to be the other name, and Django will help us actively convert it to that name.
<form action="{% url ‘go_form‘ %}" method="post" class="smart-green">
Like what:
- From message.views import getform
- Urlpatterns = [
- URL (R ' ^admin/', admin.site.urls),
- URL (R ' ^form_go/$ ', getform,name=' go_form ')
- ]
"Match Order of URLs"
URLs will be configured to match from top to bottom, so if we want to be the end of the form we should remember to add the $ end symbol, such as we need to formtest, but the first match to the form will cause conflict, which directly points to the form of the HTML template
Django's URL alias