Django (web framework): How get urls from urls.py in views.py?
-
Hello, I'am new to django and I have a question. For example, I created "blog" application in my project. so, I need a blog urls in every blog page. For example list = ['blog/about','blog/today','blog/week'] I include 'from blog.urls import urlpatterns' and hard coded urlpatterns variable. but, I think this is not a healthy solution. for this job, any django class/function? thanks.
-
Answer:
That solution doesn't sound healthy at all. You might want to consider using reverse or reverse_lazy with named_urls, from django.core.urlresolvers import reverse. Then in your http://views.py you just use reverse('blog:about') and in your http://urls.py you use this: url(r'^about/$', 'blog.about.view', name='about'), Refer to official documentation: https://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns https://docs.djangoproject.com/en/dev/ref/urlresolvers/
Yaohong Ch'ng at Quora Visit the source
Related Q & A:
- How Get Free Minecraft Gift Code?Best solution by Yahoo! Answers
- How Get Promotional Codes For League Of Legends?Best solution by forums.eune.leagueoflegends.com
- How Get Get On Fb At School?Best solution by Yahoo! Answers
- How to redirect custom urls to some local IPs with pfSense?Best solution by stackoverflow.com
- How to I redirect URLS with special characters in htaccess?Best solution by Server Fault
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.