Where is django TEMPLATES - python

I need to find Django TEMPLATES location to add in a line under 'context_processors' om 'OPTIONS'
I researched and found this which looks to be my problem solver, however I am unable to find the location of the document where I am supposed to input the details specified: django.core.exceptions.ImproperlyConfigured: Enable 'django.contrib.auth.context_processors.auth'
The project only relies on Django as a plugin so I am in no means experienced with setting up Django.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
"django.contrib.auth.context_processors.auth",
]
}
}
]
I can
not find the 'TEMPLATES' document.

You put all project configurations in settings.py right at the top of the project

Related

how can i use path Django for locating and loading templates? Django 3.2

in django3.2 I was trying this to uses for locating and loading templates?
but doesn't work with me
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ` [BASE_DIR / 'templates']`,
}
default setting was like :
`from pathlib import Path`
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Any clue of what might be the problem?
try using
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
}
if you want to change your template path, you can using this in your settings.py, for example i have a "templates" directory for my templates in root of project:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
},
]
Try this edit in your Django settings.py
TEMPLATES_DIR=BASE_DIR / 'templates'(line-17)
'DIRS':[TEMPLATES_DIR,],(line-58)

Django Across All Apps

I am creating a rather large django project which will require two things. 1) I need a few template files to be accessible across all apps. 2) I need a model to be accessible across all apps. How do I go about doing that?
As far as the templates are concerned, it seems adding it to the TEMPLATES directive doesn't work.
As far as the models are concerned, can I have a models.py in the project/project folder or something like that to be accessible by all apps?
Django 1.10 and Python 3.5
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
[...]
Was able to work it out with this work around.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR + '/templates'],
'APP_DIRS': True,
'OPTIONS': {
[...]

Django - templatedoesnotexist

I'm creating a project named "crepes_bretonnes". In this project, I have an application blog. I created a template date.html. Here is the structure of my folders :
crepes_bretonnes/
blog/
__init__.py
admin.py
migrations/
__init__.py
models.py
templates/
blog/
addition.html
date.html
tests.py
views.py
crepes_bretonnes/
__init__.py
settings.py
urls.py
wsgi.py
templates/
db.sqlite3
manage.py
When I try to see the page, I have a message templateDoesNotExist. I have read a lot about it on the web but I have not succeed in resolving my problem. In fact, I don't understand why Django does not search in my template folder of the app blog although I wrote "blog" in INSTALLED_APP in setting.py. Obviously, I have put TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),) in setting.py. I also tried to change the dictionary TEMPLATES. However, if I have understood well, it has no link as here Django should find my template even without this.
I don't have any solution.
Thank you for your help.
PS: If I put date.html in the general template folder and I arrange some lines, it works. However that is not a solution, I would like to respect a good structure.
UPDATE:
Thank you for your answer. Yes it really says INSTALLED_APPS in my setting and APP_DIRS is already True.
Here is my TEMPLATES in setting.py:
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',
],
},
},
]
UPDATE:
The debug message shows that Django search in django.template.loaders.app_directories.Loader: /Users/benjamin/anaconda/lib/python2.7/site-packages/django/contrib/admin/templates/blog/date.html.
However I have not written anything in these folder ... I'm working in Documents. Why does Django search here and not in Documents ?
I solved it by adding forward slash "/" after 'templates':
'DIRS': [BASE_DIR / 'templates/'],
I had the same problem saying template does not exist and I solved it by changing the URL pattern in my views.py where previously I had mentioned just date.html, later I edited with blog/date.html. Hope it might help you.
I assume 'INSTALLED_APP' is a typo and it really says 'INSTALLED_APPS' in your settings. Anyway, you need to set APP_DIRS = True for templates to be found in app/templates
folders:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True, # this line is important
'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'
# ...
]
},
},
]
me having the same issue,
added the app to the INSTALLED_APPS
done, because you (and me) were using the templates not in the main app so it must be registered in the settings (like referring to the urls of the app from the main urls file)
Go to your setting.py and try something like:
os.path.join(BASE_DIR, "templates")
For example:
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',
],
},
},
]
For me, it was using rest_framework without adding it to INSTALLED_APPS.

Django TemplateView searching in wrong place

My Django structure is:
testing
contacts
__init__.py
templates
contacts
index.html
(additional modules)
testing
__init__.py
templates
testing
test.html
urls.py
(additional modules)
Inside of the main URL module, testing.urls, I have a urlconf that is as follows:
url(r'^testing/$', TemplateView.as_view(template_name='testing/test.html'))
The problem is, it keeps looking in contacts.templates.contacts for the test.html file. With the existing urlcon, the debug page says the following:
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/Library/Python/2.7/site-packages/django/contrib/admin/templates/testing/test.html (File does not exist)
/Library/Python/2.7/site-packages/django/contrib/auth/templates/testing/test.html (File does not exist)
/Users/*/Developer/django/testing/contacts/templates/testing/test.html (File does not exist)
It always defaults to the..........................^^^^^^^^^^ contacts folder for some reason. Is there some other parameters for TemplateView or template_name that can control this? Any help appreciated!
Update - Inside settings.py
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',
],
},
},
]
The testing/testing directory is not currently being searched by Django. The easiest fix is to add it to the DIRS setting:
'DIRS': [os.path.join(BASE_DIR, 'testing', 'templates')],
Another option would be to add testing to your INSTALLED_APPS setting. Then Django would find your template, since you have APP_DIRS=True. However I wouldn't recommend this, because in your case testing/testing is the special directory that contains the settings.py and root url config.
By specifying "APP_DIRS": True, you are telling django to search for template files inside each app installed. Check in settings.py whether all your apps are contained within INSTALLED_APPS. If they are, you can try to force django to look for the templates in your app.
TEMPLATES = [
{
'DIRS': [os.path.join(BASE_DIR, 'testing', 'templates')],
....
},
]

Installing eggs theme in django-oscar

I found a theme for django-oscar here :
https://github.com/eggforsale/oscar-eggs-theme
But there is no documentation available to install it.
I tried replacing the appropriate files in the oscar/templates directory but it doesn't work.
be sure you have updated the oscar template folder in the setting.py as the docs :
location = lambda x: os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', x)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
location('templates'), # templates directory of the project
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
...
'oscar.core.context_processors.metadata',
],
},
},
]
https://django-oscar.readthedocs.io/en/latest/howto/how_to_handle_statics.html

Categories