Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

226
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda