zoukankan      html  css  js  c++  java
  • PracticalDjangoProjects 笔记三

    Django URL配置是怎么工作的?简单的说,就是定义了一组URL模式并指明是如何与具体的code相匹配。

    ADMONITION: HOW DJANGO URL CONFIGURATION WORKS

    A Django URL configuration file, or URLConf, defines a list of URL patterns and indicates how they map to parts of your code. Each URL pattern has at least two parts: a regular expression that describes what the URL looks like and either a view (a Python function that can respond to HTTP requests) to map that URL to or an include, which points to a different URLConf module. The ability to include other URLConf modules makes
    it easy to define reusable and “pluggable” sets of URLs, which can be dropped into any point in your project’s URL hierarchy.

    Also, note that regular expressions are quite strict about matching. Ordinarily, a web server will be somewhat lax and treat, for example, /admin and /admin/ as the same URL, returning the same result either way. But if you specify a regular expression that ends in a slash—as I’m doing here—you must include the slash on the end when you visit that address in your browser, or the pattern will not match and you’ll get a “Page not found” error.

    ADMONITION: ORDER OF URL PATTERNS
    When Django is trying to match a URL, it starts at the top of the list of URL patterns and works its way down until it finds a match. This means that it’s better to have more specific patterns like the ^admin/ line come first, and more general patterns like the catch-all for flat pages come last; otherwise, something like the catch-all might match a URL before Django gets to the more specific pattern you actually wanted. 

    作者:Shane
    出处:http://bluescorpio.cnblogs.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    shell cut
    查询表名
    RandomAccessFile
    eclipse 背景颜色
    JAVA 获取分行符
    date time insert
    shell date time
    python
    gdg shell
    shell入门之变量测试
  • 原文地址:https://www.cnblogs.com/bluescorpio/p/1625711.html
Copyright © 2011-2022 走看看