Django: track down causes of DeprecationWarning - django

I've upgraded to Django 1.4 and now when I run my development server I get the following warning:
/home/flc/venvs/myprj/lib/python2.6/site-packages/django/views/generic/simple.py:8:
DeprecationWarning: Function-based generic views have been deprecated;
use class-based views instead.
DeprecationWarning
I have tracked down most of the causes of this and fixed them by making the following changes:
django.views.generic.simple.direct_to_template => django.views.generic.base.TemplateView
django.views.generic.simple.redirect_to => django.views.generic.base.RedirectView
etc
However, I'm still getting the warning and can't figure out what I've missed. How do I get the actual module and line in my code that is causing the DeprecationWarning?

You can use the warnings module to raise an error for DeprecationWarning.
Temporarily add the following snippet to the top of your project's urls.py:
import warnings
warnings.simplefilter('error', DeprecationWarning)
The DeprecationWarning will now raise an error, so if debug=True you'll get the familiar yellow Django error page with the full traceback.
Once you've tracked down the source of the deprecation warnings, remember to remove the snippet! Note that it may be a third party app that is causing the deprecation warnings, not your own code.
If you're new to the warnings module, you might find the page on Python module of the week to be an easier introduction than the Python docs.

You can also do this on the command line so you don't need to modify your code. For example:
python -We manage.py runserver --traceback
The official doc is here. You can use abbreviations and the e in -We stands for convert warnings to error.

Related

No module named 'django.conf.urls.defaults'

I upgraded from django 3.2.5 to django 4.0.4.
I know that this 'django.conf.urls.defaults' must be deprecated.
My problem is that I don't get this error in the development environment but when I push to production, it shows the error. Why is this so???
Also I tried to locate the file so that I can change that line of code to the correct one but could find it's location. It's giving me this path which I can't see how to get to (/workspace/.heroku/python/lib/python3.9/site-packages/django/conf/urls/__init__.py))
After trying all the possibles at my level , I had to revert to django 3.2.5

Django-Bleach or Just Bleach?

I've recently tried to implement Django-Bleach into my project, but I'm having an issue with an import library. I am currently running Python 3.6.2 and Django 1.11. When I try to define a django_bleach form in my forms.py, with the following statement:
from django_bleach.forms import BleachField
I am receiving the following error:
ModuleNotFoundError: No module named 'django.utils.importlib'
I spent the better part of this afternoon researching this error and I have come to understand that the django.utils.importlib statement was deprecated in 1.9. However, I can't seem to determine a workaround for this problem. I did try the suggestion outlined in this issue but it didn't seem to make a difference. I still receive the error. Cannot import importlib
I'm also wondering if I should be using bleach instead of django-bleach as django-bleach doesn't seem to be updated since 2014. Thanks in advance for your suggestions and help.
Package you are trying to use doesen't seem to be maintained.
Error you are facing is related to the forms.py line 7
from django.utils.importlib import import_module
If you are really into the following wrapper package you could fork/fix it and install your forked version instead
Ultimately wound up incorporating just bleach into my django installation. It appears django-bleach is no longer supported for Python 3. Using Bleach and incorporating it according to the documentation allowed me resolve this issue.

django, haystack, and pyelasticsearch best versions

Basically, I am getting a unreasonable amount of errors using these libraries:
django==1.4.3
pyelasticsearch==0.6
simplejson==3.3.0
django-haystack==2.1.0
The errors I get are:
From python2.7/site-packages/haystack/query.py:
index_queryset() got an unexpected keyword argument 'using'
I just remove this and it works locallay
/srv/www/projects/k-state-union/lib/haystack/backends/elasticsearch_backend.py:
raise MissingDependency("The 'elasticsearch' backend requires the installation of 'pyelasticsearch'. Please refer to the documentation.")
This error occurs when pyelasticsearch fails to be imported. If I let it fail naturally:
/srv/www/.virtualenvs/k-state-union/lib/python2.6/site-packages/pyelasticsearch/client.py:
from simplejson import JSONDecodeError
Which works in the python interpreter.
The errors seem to indicate that I am not using the intended versions of pyelasticsearch and haystack. What do I need to do to get this up and running?
There are two different python libraries for Elasticsearch out there. I switched from pyelasticsearch to elasticsearch and it worked.

Django 1.3 with Webassets 0.7: assets.py ignored?

I'm trying to get an existing Django project to work on my mac.
I managed to configure everything and opening the project in PyCharm.
When I run I get the error:
TemplateSyntaxError at /
Caught BundleError while rendering: 'stylesheets' not found (using staticfiles finders)
We use Django 1.3 and Webassets 0.7 (just updated from earlier versions).
I have an assets.py defined in my application folder defining the various bundles.
Any suggestions on solving this?
EDIT: Ok, a bit further ... I added my project.assest to settings and now I don't have the Bundle error. I do still have another problem:
Caught BundleError while rendering: 'styles/libs/jquery-ui-timepicker-addon.css' not found
Path look ok, collectstatic works, copies, file is in place ...
any suggestions?
A project-wide assets.py (as opposed to one in an app-directory) is no longer automatically read, you need to define such files through a ASSETS_MODULES setting now.
If you are using staticfiles, pay attention to the fact that the staticfile finders will not be used unless Django is in debug mode (settings.DEBUG=True). In production mode, webassets will assume that collectstatic has been run first.
In settings.DEBUG=True mode, the reverse is true: ONLY the Django staticfile finders will be used. You could try opening a shell (./manage.py shell) and see if the following finds your file:
from django.contrib.staticfiles import finders
finders.find('styles/libs/jquery-ui-timepicker-addon.css')
If it does, then so should webassets.
I had a similar error arise
'[BUNDLE_NAME]' not found (using staticfiles finders)
This wasn't a very helpful message, so ended up looking into ./manage.py shell and running
>>> from django.conf import settings
>>> from [ASSETS_FILE_PATH.assets] import [BUNDLE_NAME]
>>> [BUNDLE_NAME]
If this isn't there it may give you another message.

Django: Can not get django-admin.py to run anything

System: Windows 7x64
Django v. 1.4
Python v. 3.2
First time working with Django or python and I am beating my head against the wall. I have installed everything for Django according to the install instructions. The only step I skipped was the 'optional' virtualenv installation.
I am attempting to run the tutorial on djangoproject.com and I can't get startproject to work. Here is my issues.
When attempting to use 'django-admin.py startproject mysite' or even just 'django-admin.py help' functions I get the following:
Traceback (most recent call last):
File "C:\Python32\Scripts\django-admin.py", line 2, in
from django.core import management File "C:\Python32\lib\site-packages\django\core\management__init__.py",
line 54
except ImportError,e:
^
SyntaxError: invalid syntax
Where the ^ is pointing to the comma.
I have checked the permissions for the folder I am in and everything appears to be good there. What am I doing wrong?
Django doesn't work with Python 3 (yet).
Install 2.7 instead.
You might also stick to Python 3.X and get django 1.5 that is currently in beta phase.
Python 3.3 offers experimental support. django-admin.py still won't run properly, but here's a workaround for you:
You can call the django-admin subcommands directly from your own python script.
from django.core import management
management.call_command("startproject", "mysite")
Almost everything else should be done from the manage.py file it generates, which should work fine with:
python manage.py runserver
or whatever command you're looking for. You may also be using "python33" instead of python.
General answer: that syntax line isn't valid in Python 3.2 (Django doesn't work with Python 3 yet). Here's a list of the 2.x versions you can use with particular versions of Django.
Specific answer: According to PEP-3110, the syntax for exceptions changed from except Exception, e to except Exception as e in Python 3, which is why that error's showing up.