I am learning to use Django (specifically version 1.9). However, when creating a view, and when starting the Django server, I have the following error:
TypeError: render() takes at least 2 arguments (1 given)
What I do not understand is, what other parameters should the render()
method have, apart from the direction of the view (considering it is static)?
This error was corrected with the addition of missing parameters. However, now I am presented with the following error, which I do not know why it occurs:
AttributeError: 'str' object has no attribute 'regex'
In my views.py file of my application, I have the following (CORRECTED):
from django.shortcuts import render
from django.template import Template
def index(request):
template_name = '/app/web/index.html'
return render(request, template_name)
Regarding my URL file, it has the following:
from django.conf.urls import include, url
from django.contrib import admin
import app.views
urlpatterns = ['',
# Vista para pagina de inicio
url(r'^$', app.views.index),
# Otras vistas
url(r'^admin/', include(admin.site.urls)),
]'
And in the configuration file, I partially edited the templates section, adding the folder where my page is in:
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app'
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'vehiculos.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'/app/web',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'vehiculos.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'vehiculos',
'USER': 'root',
'PASSWORD': '',
# 'HOST': 'localhost'
# 'PORT': '3306',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'es-CL'
TIME_ZONE = 'America/Argentina/Mendoza'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
Thank you very much in advance