Search
 
SCRIPT & CODE EXAMPLE
 

HTML

how to link html pages in django

Django has updated urlpatterns to take 'path' instead of using url
so it's become much more efficient. You don't have to use regex anymore

from django.urls import path
from . import views

urlpatterns=[
    path('', views.index , name='index'),
    path('blog/', views.blog , name='blog'),]
Then in templates, you can use template tagging

<a href="{% url 'index' %}">Index</a>
<a href="{% url 'blog' %}">Blog</a>

If you have multiple apps, you can tag it as follows.
For example, if this is under 'post' app:

In post app urls.py:

from django.urls import path
from . import views

app_name = 'post'
urlpatterns=[
    path('', views.index , name='index'),
    path('blog/', views.blog , name='blog'),]
in the project urls.py:

from django.urls import path, include

urlpatterns=[
path('post/', include('post.urls'),]
In templates, you do as following:

<a href="{% url 'post:index' %}">Index</a>
<a href="{% url 'post:blog' %}">Blog</a>
Comment

PREVIOUS NEXT
Code Example
Html :: html5 select 
Html :: how to make an a tag not clickable 
Html :: del html 
Html :: html deactivate scrolling 
Html :: html video multiple elements 
Html :: when do i put my script in the body tags in html 
Html :: html hoover text 
Html :: bold font html 
Html :: check if OS path exists through Python 
Html :: simple html report template 
Html :: how to install font-aweseome usin npm 
Html :: variables in url_for flask jinja 
Html :: html5 audio 
Html :: how to make the border invisible in html 
Html :: multiple form submit for different form action 
Html :: html 2 classes 
Html :: The <select Element 
Html :: html input for email 
Html :: viewport 
Html :: html audio tag 
Html :: lxml.html get element by id 
Html :: flip an image js 
Html :: html table header 
Html :: form row twig symfony 
Html :: anchor tag background image html 
Html :: how to make a button in html go to another address 
Html :: alpinejs submit prevent default 
Html :: html snippet 
Html :: nested list html 
Html :: lang element html 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =