简体   繁体   中英

Django views.py not rendering and giving error

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

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM