2
There are a few issues with your setup; but nothing that’s major:
-
Your file is called
haliyikama/first/url.py
; but you are including it asurl(r'^', include('first.urls')),
(note theurls
); you need to change the name of your file tohaliyikama/first/urls.py
. -
Your patterns are also incorrect. Your pattern needs to be
^$
for the very first pattern in your url list. -
The reason
admin
is not working, is because you haven’t mapped it to any url pattern; try addingurl(r'^admin/', admin.site.urls),
to your mainurls.py
. -
href="{% url home.html %}"
this is not how you use theurl
tag, you need to pass it the name of the view, not the template; like thishref="{% url 'home' %}"
.
I also suggest you read a quick primer on regular expressions because these are important when defining urls; as they work on the concept of pattern matching.
Here are some quick tips:
Lets say you have a pattern like this url(r'^home/')
This means any url that starts with home/
, so it will match home/foo/bar/zoo/hello
along with anything else home/hello.html
etc. This is why usually when you have an “open ended” pattern like this, you usually include a lot of other urls after it, like this url(r'^home/', include('home.urls'))
.
Now, when you do url(r'^home/', include('home.urls'))
this means “any url that starts with home/, match it against the list of urls found in home/urls.py file”.
Lets say in our home/urls.py
file, we have:
url(r'^$', views.index),
This ^$
means a blank string, so views.index
will be called when the url is http://localhost:8080/home/
Here is another example:
url(r'^members/$', views.members),`
Now this will match home/members/
.
Hopefully this helps clarify the issues you are facing. Please have a read through the tutorial which covers these concepts.
0
The main problem I had was using the URL tags. If you had some problem like this and pop-up in here, here is the answer how I solve my problem with the help I get from Burhan Khalid;
Yes my url tag was wrong but instead of href=”{% url home %}” doing something like that I should have do something like href=”{% url ‘home’ %}”
there is not much difference but it will help to call the name so it can send you that link. The Url tags in the HTML file was wrong.
- [Answered ]-How to get distance field in REST response?
- [Answered ]-Second Django Logout Does Not Work
- [Answered ]-Django {%trans%} not working, despite django.po being generated