django.template.exceptions.TemplateDoesNotExist: learning_logs\base.html - python

I'm following along a project from the Python crash course book. I'm supposed to be deploying the webapp to heroku but I keep receiving a Server Error 505 warning.
The problem:
I have tried to do various things with my setings.py file, but none appear to work.
SETTINGS.PY:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [r'\learning_logs\templates\learning_logs',
r'\users\templates\users',],
'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',
],
},
}, ]
Project setup:
learning_log: 11_env learning_log:
.git
learning_log:
....
learning_logs:
templates:
learning_logs:
*all html files including base.html*
...
If anyone requires more information to answer the question, please let
me know.

Related

TemplateDoesNotExist at /accounts/ (Django With Flutter)

I am trying to connect Flutter with Django. Flutter and Django alone seems to be fine,working without error. But when i am trying to combine both together, an error pops up that says:
TemplateDoesNotExist at /accounts/
Here is the cause of the problem
from django.shortcuts import render, HttpResponse
def home(request):
return render(request, '../screens/login_screen.dart')
It says that directory does not exists.
As you see above the directory exists. What is the problem can somebody help?
Template:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
What I can see is that the screens folder is on the root but not inside the accounts folder it's self.
For that you have to explicitly mention in the templates configurations within settings. You have to mention the "BASE_DIR, 'name of the folder where the templates are'". Here how it has to be written.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'screens')],
'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',
],
},
},
]
Secondly, you have to give the path of the file within in the views in such manner.
return render(request, 'screens/login_screen.dart', context)
Hope that helps.

TemplateDoesNotExist with Django-Fobi

Alright, so I'm not that new to programming, but I still have newbie problems.
I'm using Python 2.7 , Django 1.8
I installed django-fobi around 2 days ago and have been pulling my hair since.
Things are better now, but one error refuses to resolve:
TemplateDoesNotExist at 127.0.0.1:8000/fobi/forms/create/ the template is: bootstrap3/create_form_entry.html
although the loader does find it:
project_name/fobi/contrib/themes/bootstrap3/templates/bootstrap3/create_form_entry.html (File exists)
However, the other templates of fobi are working.
To be honest, I'm not sure if I configuredfobi correctly (newbie issues).
Here are my files:
project_name/settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [(os.path.join(SETTINGS_PATH, 'templates'))],
# 'DIRS': [],
# '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',
"fobi.context_processors.theme", # Important!
"fobi.context_processors.dynamic_values", # Optional
"django.core.context_processors.request"
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'admin_tools.template_loaders.Loader',
],
# 'debug': DEBUG_TEMPLATE,
},
},
]
And I copied the fobi folder from https://github.com/barseghyanartur/django-fobi/tree/master/src and put it at project_name/fobi
Initially, when I did not have the full fobi folder copied, I had just a few templates copied to project_name/templates/bootstrap3/create_form_entry.html, and the template loaded, but then the reversed url fobi_theme.create_form_entry didn't work.
All migrations are applied and the apps are added in INSTALLED_APPS.
Please, help and thank you in advance.

Error loading admin page after upgrading to django-1.11

So previously, I was using django-1.8 version & I am in the process of upgrading to django-1.11. When I load my /admin page, I get
Exception Type: TemplateDoesNotExist
Exception Value: admin/index.html
I have tried multiple options and dont know why django is not loading admin templates for django-1.11.
Few more details:
- I use django-jet for the admin interface
- My TEMPLATES in settings looks like this:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'custom_dir_1'),
os.path.join(BASE_DIR, 'custom_dir_2'),
os.path.join(BASE_DIR, 'custom_dir_3')
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.contrib.messages.context_processors.messages',
'context_processors.base_context',
],
}
}
]
Let me know if I can provide any other information to debug better. Any guidance in this issue is super appreciated, Have been at this issue for 3rd consecutive day :-(
You must set APP_DIRS to True, i.e.:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'DIRS': [
...

Django Developments Template_DIRS setting failed

I was recently trying to learn Django for one of my private project.
When came to the Chapter on Template,the Django Book recommended setting template path in settings.py using the the following snippet
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__),'templates').replace('\\','/'),)
However ,when I opened the file setting.py I found nothing like "TEMPLATE_DIR" but a list:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'),],
'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',
],
},
},
]
the the value related to the key "DIR",was a empty list. So I try to filled it with the content shown above.
And then, code something in the views.py(all the import was done )
def current_datetime(request):
now = datetime.datetime.now()
t = get_template("current_datetime.html")
html = t.render(Context({"current_date" : now}))
return HttpResponse(html)
And then mkdir templates in the same folder with setting.py , saved current_datetime.html in folder templates
Finally,run the project.and got the message in my terminal:
WARNINGS:
?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 > and the TEMPLATES dictionary takes precedence. You must put the values of the > following settings into your default TEMPLATES dict: TEMPLATE_DIRS.
System check identified 1 issue (0 silenced).
June 15, 2017 - 15:32:49
Django version 1.11.2, using settings 'mysite.settings'
Starting development server at 127.0.0.1:8000/
Quit the server with CONTROL-C.
When opened the address (127.0.0.1:8000/time/) in my Safari,here came the
error message:
enter image description here
Anyone help,please ??
There is a warning on TEMPLATE_DIRS, for that just be sure you don't have TEMPLATE_DIRS variable in your settings.py and restart development server.
Then for the error, you are actually using a Context object instead of a dict, you should render the template using a useful shortcut https://docs.djangoproject.com/en/1.11/topics/http/shortcuts/#example
from django.shortcuts import render
def current_datetime(request):
now = datetime.datetime.now()
return render(request, "current_datetime.html", {
'current_date' : now,
})
I think you have BASE_DIR in settings.py for define location so use like below
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',
],
},
},
DIRS should be like below
'DIRS': [os.path.join(BASE_DIR, 'templates'),],

Django templates and unipath

I'm trying to use unipath module in my django project as it mentioned in Two Scoops of Django book and something works not as intended.
In my settings.py I have this:
from unipath import Path
BASE_DIR = Path(__file__).ancestor(2)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [(BASE_DIR.child('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',
],
},
},
]
STATIC_ROOT = BASE_DIR.child('static')
MEDIA_ROOT = BASE_DIR.child('media')
And with that settings I'm getting TemplateDoesNotExist exception:
Using loader django.template.loaders.filesystem.Loader:
/var/www/(Path('/home/user/my_project/project/templates'),)/myapp/index.html (File does not exist)
What am I doing wrong?
Finally solved this problem!
Need to edit TEMPLATES' 'DIRS' string in settings.py to:
'DIRS': (BASE_DIR.child('templates'),),

Categories

Resources