Django 1.6 - DeprecationWarning: Use the LOCALE_PATHS - python

After migrating project from Django 1.4 to 1.6 I've started to see a problem in the console:
/usr/lib/python2.6/dist-packages/django/utils/translation/__init__.py:63: DeprecationWarning: Translations in the project directory aren't supported anymore. Use the LOCALE_PATHS setting instead.
The message is of course pretty self-explanatory, but still would appreciate if someone can specify what has to be done to fix this.

To fix this, you have to define a LOCALE_PATHS tuple/list in your settings, as follows:
LOCALE_PATHS = ('/path/to/a/locale/directory/',) # the tuple can of course stay empty
As often, you just have to read the docs: LOCALE_PATHS

This link explains how Django performs the lookup for LOCALE files.

Related

difference between URL and path in Django?

I just started learning Django, and not able to understand that what is the actual difference between URL and path in Django.
Until Django 1.11 there was nothing called a path to define app urls. Django 2.0 introduces path as a replacement for URL. Since you have just started with Django stick with 2.0 documentation and keep in mind that every forum you check will have solutions for older versions of Django
I know that this is an older question, but to answer the question directly:
Since Django 2.0, the url() function is an alias to django.urls.re_path()
And, it is listed as deprecated since Django 3.1.
So, you should use either path() or re_path() moving forward, depending on which meets your needs.
HTTP URLs are defined in section 3.3 of RFC 1738:
An HTTP URL takes the form:
http://<host>:<port>/<path>?<searchpart>
Given a URL such as https://www.djangoproject.com/download/, the path is just /download/.
Sadly, Django often confuses paths and URLS. For example, all of the code examples for the get_absolute_url() method in the documentation return paths, not URLs.
Some parts of Django do get it right though, such as request.path and request.build_absolute_uri() which use the correct terms.

TemplateDoesNotExist at /admin/MY_APP/my_model/ reversion/change_list.html

I update a old 1.3 django site to 1.8.
The predecessor developer used django-reversion to save each change in the models.
The problem he override the admin template for some model and I get this error for ALL models:
TemplateDoesNotExist at /admin/MY_APP/my_model/
reversion/change_list.html
I found this link in google.
So I change the path in my template directory like this:
/reversion/MY_APP/ instead /admin/MY_APP
Unfortunately, this don't solve the problem.
NB: The application name is in uppercase
I'm just stupid. I forgot to add 'reversion' to INSTALLED_APPS.
THX for your answer, but I can't vote for you without 15 reputation.
add to INSTALLED_APPS.
First, I used django 1.8 and django-import-export==0.2.2, and they do not match well, and I updated to django-import-export==0.4.5

What is the Django HOST_DOMAIN setting for?

Despite googling I can't find any documentation for the Django HOST_DOMAIN setting in the settings.py.
I am going through a settings.py file I have been given and this is the only part of the file I am not 100% clear on.
You can find out what are all the django specific settings at the settings reference which lists all the settings variables (and their defaults) that are set by django.
Since settings.py is just any other Python module, you are free to define your own variables and import them in your code with:
from django.conf import settings
settings.MY_CUSTOM_SETTING
Third party applications can also define their own settings, which you can modify by entering the specific value in settings.py.
It sounds like HOST_DOMAIN is one such custom setting.
That is not a Django setting.
It's perfectly good practice to define your own project-specific settings inside settings.py, and that is presumably what the original developer did here.

Django Template Cache? Templates which don't exist are renderd

Usually I have the opposite problem, Django can't find the templates.
Lastly, I change a template of mine called custmber_view.html, but Django didn't notice the chagnes.
I tried flushing all caches, without success. In my dispair, I completely removed the template
hoping to see the familiar TemplateDoesNotExist exception.
To my surprise, Django keeps rendering the template! Although it is not found on the hard-drive.
Can someone suggest a solution to this mystery?
ARGH, legacy projects, I am doomed to fix them for ever. Somewise guy put the following in settings.py:
TEMPLATE_DIRS = (
os.path.join(project_dir, u'templates'),
u'/var/www/venv2.7/lib/python2.7/site-packages/backoffice/templates',
)
I feel like this now ...
So, conclusion, If you are working on a project which was not made as a Django App, always make sure you read the variable TEMPLATE_DIRS.
But for your colleagues future (and for better moral) always follow How to write reusable Django app

Why don't I have any comments in my py-files? (Django)

I'm following this tutorial about creating a simple blog with Django. I see that this guy has a lot of comments in his py-files with explanations and such. My py-files don't look at all the same. For example, in settings.py I don't have any varibale called TEMPLATE_DIRS, but in this guys file it looks like this:
TEMPLATE_DIRS = (
"",
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
Since I'm a newbie I would of course appreciate the help that these comments and pre-defined variables provide. Why don't I have them? Have Django removed them in a later version?
Thanks in advance!
Perhaps the answer is here
Its because of your django version that you are using. in this tutorial they used django 1.3. its
existing in the django 1.3. But Its misssing in djang 1.4 and later versions.
So add the below code in your settings.py
from os.path import join
TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'),
)
It may be that the author of the tutorial wrote his own comments so that readers would better understand each of the settings. It may also be that in a newer version of Django the core developers thought it would be simpler to leave them out of the default settings file created.
It doesn't matter much because each setting such as TEMPLATE_DIRS has a default value. So you can check django documentation for their meaning.

Categories

Resources