Django for Designers: Difference between revisions

Content added Content deleted
imported>Aldeka
imported>Aldeka
Line 311: Line 311:
Django starts at the first regular expression and makes its way down the list, comparing the requested URL against each regular expression until it finds one that matches.
Django starts at the first regular expression and makes its way down the list, comparing the requested URL against each regular expression until it finds one that matches.


You might ask, “What’s a regular expression?” Regular expressions, or "regexes", are patterns for matching text. In this case, we’re matching the URLs people go to, and using regular expressions to match whole ‘groups’ of them at once. (If you’d like to learn more about regular expressions, read the [Dive into Python guide to regular expressions http://diveintopython.net/regular_expressions/index.html] sometime. Or you can look at this [xkcd http://xkcd.com/208/]. [Regexpal http://regexpal.com/] is also a super helpful tool for writing a regex.)
You might ask, “What’s a regular expression?” Regular expressions, or "regexes", are patterns for matching text. In this case, we’re matching the URLs people go to, and using regular expressions to match whole ‘groups’ of them at once. (If you’d like to learn more about regular expressions, read the [http://diveintopython.net/regular_expressions/index.html Dive into Python guide to regular expressions] sometime. Or you can look at this [http://xkcd.com/208/ xkcd]. [http://regexpal.com/ Regexpal] is also a helpful tool for writing a regex.)


In addition to matching text, regular expressions can capture text. Capturing means to remember that part of the string, for later use. Regexes use parentheses () to wrap the parts they’re capturing.
In addition to matching text, regular expressions can capture text. Capturing means to remember that part of the string, for later use. Regexes use parentheses () to wrap the parts they’re capturing.
Line 321: Line 321:
<source lang="bash">django-admin.py startproject myproject</source>
<source lang="bash">django-admin.py startproject myproject</source>


to create our project way back when, Django created a default URLconf file called `urls.py` inside myproject/.
to create our project way back when, Django created a default URLconf file called 'urls.py' inside myproject/.


To write our app's URLs, edit the file myproject/urls.py so it looks like this:
To write our app's URLs, edit the file myproject/urls.py so it looks like this: