Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

render template in django

from django.shortcuts import render

return render(request, 'index.html')
Comment

django render template

from django.http import HttpResponse
from django.template import loader

from .models import Question


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    template = loader.get_template('polls/index.html')
    context = {
        'latest_question_list': latest_question_list,
    }
    return HttpResponse(template.render(context, request))
Comment

Render Django Template

views.py
def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")
def hello(request):
   return render(request, 'hello.html', {})
   
urls.py
from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
    path('hello', views.hello, name="index")
] 

templates/hello.html
<b>fdsfdsfldsjflkdsjkflksja;fdsfdsfldsjflkdsjkflksjasdfkldsjflkdsjfds</b>
<b>>fdlksjfdsljfldsjflkds</b>

Comment

PREVIOUS NEXT
Code Example
Python :: np random seed 
Python :: how to skip next 5 iteration in python 
Python :: python comment multiple lines 
Python :: remove string punctuation python 3 
Python :: python create env ubuntu 
Python :: python curve fitting 
Python :: split data train python 
Python :: make a nested list flat python 
Python :: try except keyerror 
Python :: how to insert item last in list python 
Python :: finding the rows in a dataframe where column contains any of these values python 
Python :: how to add rows to empty dataframe 
Python :: python package version 
Python :: flask error 
Python :: basic pygame window 
Python :: python get file name without dir 
Python :: how to do a foreach loop in python 
Python :: python printing variables 
Python :: python list unique in order 
Python :: df rename columns 
Python :: move all files in directory with shutils 
Python :: python slice dictionary 
Python :: list the available fonts matplotlib 
Python :: python cross validation 
Python :: extract zip file in python zipfile 
Python :: get title beautifulsoup 
Python :: saving model in pytorch 
Python :: async sleep python 
Python :: django id 
Python :: python float to decimal 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =