The questions I've had during my learning process.

Id Question Solved at
1 How do you install? Solved
2 How do you start developing? Solved
3 How do you make graphics with Django? Solved
4 Django uses some kind of structure to tell the application where to look for links. How does this hierarchy work? What is actually put into the different files? Solved
5 What is the most basic way to add the url:s to urls.py? Solved
6 What is the " '^ " thing that can be seen in the URLpatterns? Solved
7 What is the $ sign in the URLpatterns? Solved
8 If I want to embed an iframe to the app can I do it straight into the HTML? Pending
9 Are all of the URLpatterns always put into the urls.py file? Pending
10 Is it difficult to change to the production server? Pending
11 How do I really get an external CSS sheet working? Pending
12 How do I connect a new app that I've created under the project folder to the project? Pending
13 What's the development process if I want to create a new website with apps? Something discovered
14 How do you cross query models? For example, If I have a blog app and a books app, how can I show related blog posts in my books app? Pending
15 How do I take the admin interface into use? Solved
16 How do I alter the models I already have? Pending
17 How do I customize what is shown and can be edited in the admin interface? Solved
18 When I want to start developing after some time, how do I start the server and check the page etc? Pending

Thursday 14 May 2009

Sparks Capturing Learning Django #4

This time I've only got some questions and some new answers... Nothing special. I think I'll have to cut back a bit on the specific questions. It just takes too much time, and it's all Googlable, so it's not really capturing my learning process anyways.

Questions:


4. Django uses some kind of structure to tell the application where to look for links. How does this hierarchy work? What is actually put into the different files?

Ok, I've understood some more about the hierarchy. Under the project root, you have one views-file, for example views.py, where you add view functions. View functions are such functions that take a request as a parameter and return a HttpResponse. Ok, in correct language its that a view function takes aHttpRequest as a parameter and returns an instance of HttpResponse. Great. [file hierarchy, views, view functions]

5. What is the most basic way to add the url:s to urls.py?

The url:s you add are called URLpattern :s . You add them simply by adding stuff to the urls.py file. First you import the function by "from thesite.nameofviewfile import functionName". So you need to have a view file in the project root (if you create a project called test, the root is at test/ That's also where the urls.py file resides. Then after adding the import you add the following line after the statement "urlpatterns = patterns('', (Which is already in the urls.py file) : ('^functionName/$', functionName), [url, urlpatterns]

6. What is the " '^ " thing that can be seen in the URLpatterns?

That was fast! The caret "^" means: "make sure that the pattern matches the start of the string:" [^]

7. What is the $ sign in the URLpatterns?

The dollar sign means: require that the pattern matches the end of the string. [$]

The dollar and caret signs are used to show what url:s to match to the specified... thing. if you have a caret (^), it means that the url has to start with that. aasch, it's well explained here:

"his concept is best explained by example. If we had instead used the pattern '^hello/' (without a dollar sign at the end), then any URL starting with /hello/ would match, such as /hello/foo and /hello/bar, not just /hello/. Similarly, if we had left off the initial caret character (i.e., 'hello/$'), Django would match any URL that ends with hello/, such as /foo/bar/hello/. If we had simply used hello/, without a caret or dollar sign, then any URL containing hello/ would match, such as /foo/hello/bar. Thus, we use both the caret and dollar sign to ensure that only the URL /hello/ matches — nothing more, nothing less."
(From Djangobook.com) [$,^]

8. If I want to embed an iframe to the app can I do it straight into the HTML?

9. Are all of the URLpatterns always put into the urls.py file?

10. Is it difficult to change to the production server?

11. How do I really get an external CSS sheet working?

No comments: