python - Getting this error in django "ModuleNotFoundError at /myapp/" -
i using django version 11.3. create separate html template file , import in views.py file when run file gives me error.
modulenotfounderror @ /myapp/
no module named 'django.templates'
my settings.py file code:
templates = [ { 'backend': 'django.templates.backends.django.djangotemplates', 'dirs': [os.path.join(base_dir, 'templates')] , 'app_dirs': true, 'options': { 'context_processors': [ 'django.templates.context_processors.debug', 'django.templates.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]
views.py file:
from django.http import httpresponse django .template import loader .models import album def myapp(request): all_albums = album.objects.all() template = loader.get_template('myapp/index.html') context = { 'all_albums': all_albums, } return httpresponse(template.render(context, request)) def detail(request, id): return httpresponse("<h1>your requested numbers is: " + str(id) +"<h2>") html file:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>this list item</title> </head> <body> <ul> {% in all_albums %} <li><a href="/myapp/{{ a.id }}">{{ a.artist }}</a></li> {% endfor %} </ul> </body> </html> directory structure:
myapp > templates > myapp > index.html
you must use django.template without s:
templates = [{ 'backend': 'django.template.backends.django.djangotemplates', 'dirs': [os.path.join(base_dir, 'templates')], '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', ], }, }]`
Comments
Post a Comment