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 :: dictionary with list as value py 
Python :: python binary string to int 
Python :: check type of django messages 
Python :: How to convert string date to datetime format in python 
Python :: notion python api 
Python :: sum first 100 integers in python 
Python :: queue python 
Python :: python array append 
Python :: suppress python vs try/except 
Python :: python find index of first matching element in a list 
Python :: catalan number 
Python :: how to import opencv in python 
Python :: python find difference between lists 
Python :: how to get int input in python 
Python :: tqdm range python 
Python :: how to change case of string in python 
Python :: reset_index(drop=true) 
Python :: python opencv subtract two images 
Python :: if name 
Python :: check if year is leap python 
Python :: how to update sklearn 
Python :: end python print with space 
Python :: python if condition assignment in one line 
Python :: jupyter tabnine for jupyter notebook 
Python :: pandas split column with tuple 
Python :: disable close button in tkinter 
Python :: Write a Python program to sum all the items in a dictionary. 
Python :: python password checker 
Python :: how to read panda column 
Python :: python execute function from string 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =