Reputation: 1
Why is this showing an undefined variable request.
views.py
from django.shortcuts import render,redirect
from F_UI import models
def blocks():
if request.method=="GET":
return render(request,"blocks.html")
Upvotes: 0
Views: 719
Reputation: 1
You need to add a request parameter in a view.
Like this:
def blocks(request):
pass
Django will pass the HttpRequest object when calling it.
Django uses request and response objects to pass state through the system. When a page is requested, Django creates an HttpRequest object that contains metadata about the request. Then Django loads the appropriate view, passing the HttpRequest as the first argument to the view function.
Documentation link
Upvotes: 0
Reputation: 2798
Add request
as positional parameter, like so:
def blocks(request, *args, **kwargs):
if request.method=="GET":
return render(request,"blocks.html")
Upvotes: 1