Django1.7 'RemovedInDjango19Warning' when using apache with mod_wsgi - django

i am using Django version 1.7 for an application,
everything was running good in my developpement PC (i was runnin it using manage.py runserver command.
now i am trying to move it to a production server.
in the production server, everything is still good when running the server using the manage.pycommand.
but accessing the application remotely (via apache2 & mod_wsgi), i get an RemovedInDjango19Warning Exception.
after looking for a solution all i could find is how to ignore theses warnings for manage.py which don't work for me and i don't know how to disable this warnings from wsgi ?
Traceback:
Environment:
Request Method: GET
Request URL: http://192.168.0.17/
Django Version: 1.7.1
Python Version: 3.4.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'rest_framework',
'rest_framework_nested',
'django_gravatar',
'authentication',
'djcelery',
'job',
'seed',
'proxies',
'emails')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in get_response
98. resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python3.4/dist-packages/django/core/urlresolvers.py" in resolve
343. for pattern in self.url_patterns:
File "/usr/local/lib/python3.4/dist-packages/django/core/urlresolvers.py" in url_patterns
372. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python3.4/dist-packages/django/core/urlresolvers.py" in urlconf_module
366. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python3.4/importlib/__init__.py" in import_module
109. return _bootstrap._gcd_import(name[level:], package, level)
File "/var/www/cvc.ma/CapValue/urls.py" in <module>
6. url(r'^api/v1/auth/', include('authentication.urls')),
File "/usr/local/lib/python3.4/dist-packages/django/conf/urls/__init__.py" in include
28. urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.4/importlib/__init__.py" in import_module
109. return _bootstrap._gcd_import(name[level:], package, level)
File "/var/www/cvc.ma/authentication/urls.py" in <module>
2. from authentication.views import LoginView, LogoutView
File "/var/www/cvc.ma/authentication/views.py" in <module>
4. from rest_framework import permissions, viewsets, status, views
File "/usr/local/lib/python3.4/dist-packages/rest_framework/viewsets.py" in <module>
24. from rest_framework import views, generics, mixins
File "/usr/local/lib/python3.4/dist-packages/rest_framework/views.py" in <module>
11. from rest_framework.request import Request
File "/usr/local/lib/python3.4/dist-packages/rest_framework/request.py" in <module>
20. from rest_framework.settings import api_settings
File "/usr/local/lib/python3.4/dist-packages/rest_framework/settings.py" in <module>
22. from django.utils import importlib, six
File "/usr/local/lib/python3.4/dist-packages/django/utils/importlib.py" in <module>
10. RemovedInDjango19Warning, stacklevel=2)
Exception Type: RemovedInDjango19Warning at /
Exception Value: django.utils.importlib will be removed in Django 1.9.

It's happening because the django.utils.importlib module is removed in Django 1.9, in favor of the importlib in the standard library. Django Rest Framework still uses it.
You can disable the warning by following the instructions on the accepted answer of this question -- How to suppress the deprecation warnings in Django?

Finally, i ended up upgrading to Django1.9 and fixed the migration bugs.

If you just want to silence the warning in mod_wsgi, you may add a configuration directive such as:
WSGIPythonWarnings ignore::DeprecationWarning::
See this blog entry, the release notes (point 15) and the original issue.
In essence, mod_wsgi had no equivalent to the -W control option, so a directive was added. The default must have been kept at "log everything" to be consistent across different wsgi apps.

Related

Why is django getting stuck on loading a template that doesn't exist?

I've made some changes to my website's theme and have come across an issue. My previous landing page was called home.html. It worked fine. I have since changed it, retired the old pages (moved them to another folder), and put a new set of pages in my template/app/ folder. The new landing page is index.html. I have changed it in urls.py, and in views.py. I come across this error, Django still wants to access or load main/home.html. I don't understand why, even after changing it to return a HttpResponse, it still wants to render a template? What's going on?
Environment:
Request Method: GET
Request URL: https://website.com
Django Version: 3.1.4
Python Version: 3.6.9
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main.apps.MainConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template loader postmortem
Django tried loading these templates, in this order:
Using engine django:
* django.template.loaders.app_directories.Loader: /usr/local/lib/python3.6/dist-packages/django/contrib/admin/templates/main/home.html (Source does not exist)
* django.template.loaders.app_directories.Loader: /usr/local/lib/python3.6/dist-packages/django/contrib/auth/templates/main/home.html (Source does not exist)
* django.template.loaders.app_directories.Loader: /var/www/app/main/templates/main/home.html (Source does not exist)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/app/main/views.py", line 103, in homepage
return HttpResponse("well?")
File "/usr/local/lib/python3.6/dist-packages/django/shortcuts.py", line 19, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader.py", line 61, in render_to_string
template = get_template(template_name, using=using)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader.py", line 19, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
Exception Type: TemplateDoesNotExist at /
Exception Value: main/home.html
ofcourse the source does not exist, i don't want it to. Why isn't it rendering the HTTPResponse? Even after I change the render to refer to template_name ="main/index.html" explicitly the issue persists.
Thanks to Boma Anjang. I just needed to restart the server.
systemctl reload apache2

Django ImportError: cannot import name get_permission_codename

I am doing the tango with django tutorial. I am up to chapter 5 on working with models and I am setting up the admin website. I get this strange error:
ImportError: cannot import name get_permission_codename
This seems to go away when I remove the
admin.autodiscover()
from my project/urls.py. But I am concerned that I will need this down the road.
Here is the Traceback I get when I run the development server:
Environment:
Request Method: GET Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.5.4 Python Version: 2.7.3 Installed Applications:
('django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django.contrib.messages', 'django.contrib.staticfiles',
'django.contrib.admin', 'rango') Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback: File
"/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py"
in get_response
103. resolver_match = resolver.resolve(request.path_info) File
"/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py"
in resolve
319. for pattern in self.url_patterns: File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py"
in url_patterns
347. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File
"/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py"
in urlconf_module
342. self._urlconf_module = import_module(self.urlconf_name) File
"/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in
import_module
35. import(name) File "/home/gpanterov/MyProjects/django/tango_with_django_project/tango_with_django_project/urls.py"
in
6. admin.autodiscover() File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/init.py"
in autodiscover
29. import_module('%s.admin' % app) File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in
import_module
35. import(name) File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/admin.py"
in
5. from django.contrib.admin.checks import InlineModelAdminChecks File
"/usr/local/lib/python2.7/dist-packages/django/contrib/admin/checks.py"
in
6. from django.contrib.admin.utils import get_fields_from_path, NotRelationField, flatten File
"/usr/local/lib/python2.7/dist-packages/django/contrib/admin/utils.py"
in
6. from django.contrib.auth import get_permission_codename
Exception Type: ImportError at /admin/ Exception Value: cannot import
name get_permission_codename
When I remove the admin.autodiscover() line, the development server runs and I am able to get to the admin panel, but when I log in with the superuser password I created earlier, I get the message "You don't have permission to edit anything." and I don't see any of the categories I created.
I got this error when downgrading django from latest version (1.8) to an old version (1.4) for testing.
The problem here is that git doesn't delete .pyc files when switching branches (because they are .gitignore'ed) and python only regenerates them when the corresponding .py file is newer than the .pyc file (see this question for details).
The solution is to delete all *.pyc files in django/contrib/admin and django/contrib/contenttypes directories.
cannot import name get_permission_codename
Make sure u have not install all the version of django in your system.
if there then remove all and install fresh django

Django Paypal Import Error

Probably, it's stupid question. I'm using Django 1.7 & Python 2.7. I have successfull installed django 0.1.5 by running python manage.py runserver / validate. However, when I open up my view I got No module named standard.forms error. I'm using virtualenvwrapper as well. Can someone help me to shed any light?
Environment:
Request Method: GET
Request URL: http://localhost:8000/manager/paypal_payment/
Django Version: 1.7.1
Python Version: 2.7.8
Installed Applications:
('profilesite','portal','manager','qrcode','account','paypal.standard.ipn','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'account.middleware.LocaleMiddleware',
'account.middleware.TimezoneMiddleware')
Traceback:
File "/Users/eeldwin/.virtualenvs/fbt/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
98. resolver_match = resolver.resolve(request.path_info)
File "/Users/eeldwin/.virtualenvs/fbt/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
345. sub_match = pattern.resolve(new_path)
File "/Users/eeldwin/.virtualenvs/fbt/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
345.sub_match = pattern.resolve(new_path)
File "/Users/eeldwin/.virtualenvs/fbt/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
224. return ResolverMatch(self.callback, args, kwargs, self.name)
File "/Users/eeldwin/.virtualenvs/fbt/lib/python2.7/site-packages/django/core/urlresolvers.py" in callback
231. self._callback = get_callable(self._callback_str)
File "/Users/eeldwin/.virtualenvs/fbt/lib/python2.7/site-packages/django/utils/lru_cache.py" in wrapper
101. result = user_function(*args, **kwds)
File "/Users/eeldwin/.virtualenvs/fbt/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_callable
97. mod = import_module(mod_name)
File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/Users/eeldwin/Documents/Django/fbt/manager/views/pp_ipn.py" in <module>
1. from paypal.standard.forms import PayPalPaymentsForm
Exception Type: ImportError at /manager/paypal_payment/
Exception Value: No module named standard.forms
Make sure that you don't have a paypal.py file in your apps. If that's the case, you'll need to delete paypal.pyc too.

ViewDoesNotExist at /accounts/register/ (django-registration-me error)

I am currently working on a project which uses mongoengine and django. I am using django-registration-me to handle user registrations, but I am having problems after submitting the new user registration form.
The error I am receiving is:
"ViewDoesNotExist at /accounts/register/" "Tried settings in module
core.views. Error was: 'module' object has no attribute 'settings'"
It sends a verification email out fine though. I am new to django and mongoengine, so any help with this would be greatly appreciated.
The traceback is below.
Environment:
Request Method: POST Request URL:
http://dev.teamfit.us:8000/accounts/register/
Django Version: 1.3 beta 1 SVN-15207
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'registration']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File
"/usr/src/django-trunk/django/core/handlers/base.py"
in get_response
111. response = callback(request,
*callback_args, **callback_kwargs)
File
"/usr/local/lib/python2.6/dist-packages/django_registration_me-0.7-py2.6.egg/registration/views.py"
in register
153. return HttpResponseRedirect(success_url or
reverse('registration_complete'))
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in reverse
390. *args, **kwargs)))
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in reverse
311. possibilities = self.reverse_dict.getlist(lookup_view)
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in _get_reverse_dict
228. self._populate()
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in _populate
219. lookups.appendlist(pattern.callback,
(bits, p_pattern))
File
"/usr/src/django-trunk/django/core/urlresolvers.py"
in _get_callback
169. raise ViewDoesNotExist("Tried %s in module
%s. Error was: %s" % (func_name,
mod_name, str(e)))
Exception Type: ViewDoesNotExist at
/accounts/register/
Exception Value: Tried settings in
module core.views. Error was: 'module'
object has no attribute 'settings'
I guess, you have
import settings
or some such variation in your code.
You should change it to:
from django.conf import settings
and it should work

Django deployment - can't import app.urls

I just moved a django project to a deployment server from my dev server, and I'm having some issues deploying it. My apache config is as follows:
<Location "/">
Order allow,deny
Allow from all
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE project.settings
PythonDebug On
PythonPath "['/home/django/'] + sys.path"
</Location>
Django does work, since it renders the Django debug views, but I get the following error:
ImportError at /
No module named app.urls
And here is all the information Django gives me:
Request Method: GET
Request URL: http://myserver.com/
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.admindocs',
'project.app']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware')
Traceback:
File "/usr/lib64/python2.6/site-packages/django/core/handlers/base.py" in get_response
83. request.path_info)
File "/usr/lib64/python2.6/site-packages/django/core/urlresolvers.py" in resolve
218. sub_match = pattern.resolve(new_path)
File "/usr/lib64/python2.6/site-packages/django/core/urlresolvers.py" in resolve
216. for pattern in self.url_patterns:
File "/usr/lib64/python2.6/site-packages/django/core/urlresolvers.py" in _get_url_patterns
245. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib64/python2.6/site-packages/django/core/urlresolvers.py" in _get_urlconf_module
240. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib64/python2.6/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
Exception Type: ImportError at /
Exception Value: No module named app.urls
Any ideas as to why I get an import error?
Add the project directory to sys.path.
My guess is that if you simply change your url configuration to reference "project.app.urls" instead of "app.urls", your problem will be fixed.
It seems that you've listed "project.app" in INSTALLED_APPS in your project's settings.py file, but you've referenced "app.urls" in your urls.py. You need to standardize and either always reference "app", and change your PythonPath to include the project directory, or always reference "project.app".
I would recommend to use virtualenv along with mod_python. Some instructions here: http://mydjangoblog.com/2009/03/30/django-mod_python-and-virtualenv/
It has the advantage of solving all your path problems, but also to allow to install extra modules (or even other versions of django) very easily.