I am currently learning Django with video tutorials and I came across a problem I can't get rid of. I am in the views file of one of my apps and when I try to use "request" it tells me '"request" is not definedPylancereportUndefinedVariable'
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def home_view(*args, **kwargs):
return render(request, "home.html", {})
def contact_view(*args, **kwargs):
return HttpResponse("<h1>contact page</h1>")
I tried importing HttpRequests and modifying the code to fit but it then tells me that it doesn't have a META attribute when I run the server runserver error
I'd like to use "request" and not import a new library for it as it should come with django, the guy in the tutorial I watch just types in request and it works.I couldn't find anything in the Django docs and it seems like using request shouldn't even be an issue.
request
is the first parameter of a view function, you thus need to specify this explicitly:
# ↓ request parameter
def home_view(request, *args, **kwargs):
return render(request, 'home.html', {})