Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
Why am I getting name 'request' is not defined?

I'm following a Django tutorial and have reached the point of using return renderand currently my views.py looks like this:

from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
def construction_view(*args, **kwargs):
    return HttpResponse("<h1> This site is currently being constructed. Please check back later </h1>")

def home_view(*args, **kwargs):
    return render(request, "home.html", {})

I am getting an error whien trying to go to my home page:

views.py", line 9, in home_view
    return render(request, "home.html", {})
NameError: name 'request' is not defined

Not sure what is causing this as according to Django docs request is part of render which is imported above.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

request is always the first parameter of any view. In your view, your function only has *args and **kwargs, so request will be the first item in the args. It is better to make the request parameter explicit and work with:

#        request ↓
def home_view(request, *args, **kwargs):
    return render(request, "home.html", {})

Since you likely only use this view for URL patterns without URL patterns, you can probably omit the *args and **kwargs:

#                  ↓ omit *args and **kwargs
def home_view(request):
    return render(request, "home.html", {})
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda