Django's URL alias

Source: Internet
Author: User

urls.py configuration file for the project

    1. From message.views import GetForm
    2. Urlpatterns = [
    3. URL (r ' ^admin/', admin.site.urls),
    4. URL (r ' ^form/$ ', getform)
    5. ]

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

    1. From message.views import getform
    2. Urlpatterns = [
    3. URL (R ' ^admin/', admin.site.urls),
    4. URL (R ' ^form/$ ', getform,name=' go_form ')
    5. ]
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:

    1. From message.views import getform
    2. Urlpatterns = [
    3. URL (R ' ^admin/', admin.site.urls),
    4. URL (R ' ^form_go/$ ', getform,name=' go_form ')
    5. ]

"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.