i'm new in python world and i'm using python 3.4 and django 1.7
When o put DEBUG=True in settings.py the browser shows me an error like:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
C:\workspace_virtualenv34\prog\prog\templates\main_sites\registration\login.html (File does not exist)
But my templates are in a different path:
C:\workspace_virtualenv34\prog\templates\
In settings.py i set ROOT_PATH as:
ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname( file ), os.pardir))
Is there anyway to turn back path levels that solve this problem?
Thanks.
You should be able to provide any directories to TEMPLATE_DIRS that django will use to search for templates
https://docs.djangoproject.com/en/1.8/ref/settings/#template-dirs
you should be able to construct this using the ROOT_PATH to avoid referencing absolute paths directly; change for your specific path:
TEMPLATE_DIRS = (
os.path.join(ROOT_PATH, '..', '..', 'prog', 'templates'
)
Related
trying to deploy my app to uwsgi server
my settings file:
STATIC_ROOT = "/home/root/djangoApp/staticRoot/"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/home/root/djangoApp/static/',
]
and url file:
urlpatterns = [
#urls
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
and if I try to execute the command:
python manage.py collectstatic
Then some files are okay ( admin files ), but I see an error next to files from static folder. The error is like:
Found another file with the destination path 'js/bootstrap.min.js'. It
will be ignored since only the first encountered file is collected. If
this is not what you want, make sure every static file has a unique
path.
and have no idea what can I do to solve it.
Thanks in advance,
The two paths you have in STATICFILES_DIRS are the same. So Django copies the files from one of them, then goes on to the second and tries to copy them again, only to see the files already exist.
Remove one of those entries, preferably the second.
do you have more than one application?
If so, you should put any file on a subdirectory with a unique name (like the app name for example).
collectstatic collects files from all the /static/ subdirectories, and if there is a duplication, it throw this error.
I included the path to my templates folder in the settings.py file by setting:
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
and likewise for STATIC_FILES_DIR, but I keep getting the TemplateDoesNotExist error. When I look at the postmortem of the error, I see:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
C:\Python27\lib\site-packages\django\contrib\admin\templates\home.html (File does not exist)
C:\Python27\lib\site-packages\django\contrib\auth\templates\home.html (File does not exist)
Why would the template.loader be looking for the template files in that directory instead of the one specified in my settings.py file? Also, when I copy over my home.html page into the first directory mentioned in the error message, the page loads the content without error, so how can I get the loader to move from the location that it's searching to the directory where the files are actually located?
Valid setting name is TEMPLATE_DIRS and it is a tuple of strings, not the simple string:
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'), )
I'm getting a 400 error when trying to access the /admin/filebrowser/browse/ page. I followed the instructions as per https://django-filebrowser.readthedocs.org/en/3.5.2/quickstart.html and have my URLs and installed apps configured correctly.
What I'm not too sure about are the media paths in settings.py;
FILEBROWSER_DIRECTORY = os.path.join(BASE_DIR, '/ogencat/MEDIA/uploads')
FILEBROWSER_MEDIA_ROOT = os.path.join(BASE_DIR, '/ogencat/MEDIA')
FILEBROWSER_MEDIA_URL = '/MEDIA/'
I have folder in my workspace called MEDIA and a folder within called uploads.
I wasn't too sure about what the docs wanted me to do in terms of setting these paths - I hadn't seen the getattr(settings, "FILEBROWSER_MEDIA_ROOT", settings.MEDIA_ROOT) syntax before so I just added the paths as I have done for the rest of settings.py
Thanks!
You need to add trailing slashes
Directories must exist prior accessing them
I'm trying to deploy django project to webfaction and stuck with the problem that the server does not see my templates folder
PROJECT_DIR = os.path.dirname((os.path.dirname((os.path.dirname(__file__)))))
TEMPLATE_DIRS = (
os.path.join(PROJECT_DIR,'templates'),
)
python path in httpd.conf :
python-path=/home/wadadaaa/webapps/promo_site/myproject:/home/wadadaaa/webapps/promo_site/lib/python2.7
And i have exception:
Exception Type: TemplateDoesNotExist
Exception Value: index.html
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/home/wadadaaa/webapps/promo_site/templates/index.html (File does not exist)
any ideas how to fix it?
When deploying to WebFaction I add the project's parent directory to the python_path:
python-path=/home/wadadaaa/webapps/promo_site:/home/wadadaaa/webapps/promo_site/myproject:/home/wadadaaa/webapps/promo_site/lib/python2.7
If you're using Django 1.5.x, a common way I "map" directory paths like TEMPLATE_DIRS, STATIC_ROOT, etc, is to use a function to compute those. This is especially useful if you work on more than one machine, or in a group, where the path to these files is going to vary per-developer:
# settings.py
import os
def map_path(directory_name):
return os.path.join(os.path.dirname(__file__),
'../' + directory_name).replace('\\', '/')
...
TEMPLATE_DIRS = (
map_path('templates'),
)
This is a convenient way to map your templates directory, given a project structure of:
my_app/
my_app/
__init__.py
settings.py
...
a_module/
__init__.py
models.py
templates/
layouts/
base.html
index.html
...
I use django-compressor 1.1.2 with Django 1.4 when using compress templatetags PROJECT_PATH appended to STATIC_URL after compression
/static/Users/sultan/.virtualenvs/mediabox/somedia/somedia/public/media/media-cache/compressor/css/1d7cd4216904.css
When I don't set
COMPRESS_OUTPUT_DIR = os.path.join(MEDIA_CACHE, 'compressor')
Output looks like
/static/CACHE/css/1d7cd4216904.css
settings
STATICFILES_FINDERS = (
...
'compressor.finders.CompressorFinder'
)
COMPRESS_ENABLED = True
COMPRESS_OUTPUT_DIR = os.path.join(MEDIA_CACHE, 'compressor')
What is wrong with my configuration?
Thanks,
Sultan
According to the doc
django.conf.settings.COMPRESS_OUTPUT_DIR
Default : 'CACHE'
Controls the directory inside COMPRESS_ROOT that compressed files will be written to.)
I don't know what's your MEDIA_CACHE setting here, but you don't need to join directories to generate COMPRESS_OUTPUT_DIR, just give it a relative name such as 'compressor' or 'cache' to try.