Answer the question
In order to leave comments, you need to log in
How to master url magic in Django?
Hello, I recently started dipping into the back-end and started with Django (I poked around the tutorials, it worked, but there was a snag and understanding "why is it not working ?!" is not possible at the moment.
I create a view for the pages and specify them in controller.
def index(request):
return render(request, 'blog/index.html')
def post_list(request):
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
return render(request, 'blog/post_list.html', {'posts': posts})
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'', include('blog.urls')),
url(r'^post_list/', include('blog.urls')),
]
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^$', views.post_list, name='post_list'),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
if settings.DEBUG:
urlpatterns += [
url(r'^images/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}),
]
{% url "post_list" %}
Answer the question
In order to leave comments, you need to log in
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'', include('blog.urls')),
url(r'^post_list/', include('blog.urls')),
]
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^$', views.post_list, name='post_list'),
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question