How do I do cron job for list of URLS?

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

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

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.