Reputation: 5
i have an app called play, inside it i have made a templates folder and hello.html is saved there, in views.py I render hello.html it says hello is not defined
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/play/hello/
Django Version: 3.1.1
Python Version: 3.8.12
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'play']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "C:\Users\harsh\anaconda3\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\harsh\anaconda3\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "G:\My Data\Programing\django\store\play\views.py", line 6, in say_hello
return render(request, hello.html)
Exception Type: NameError at /play/hello/
Exception Value: name 'hello' is not defined
Upvotes: 0
Views: 117
Reputation: 3350
hello.html
should be a String. This is the path to yours Template.
# the path should be relative to the 'templates/' directory
return render(request, 'path/to/hello.html')
Upvotes: 1