ImportError: cannot import name get_path_info - django

My question is why foreman start not serving css file in dev environment ...? but my app running perfectly fine in heroku production server. Correct me if i am wrong, i thought dj-static is the only option for serving static in foreman env, so in order to work dj-static in wsgi.. follows...
wsgi.py
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
if i am changing above code to
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "readtamil.settings")
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
then foreman start gives me this error
ImportError: cannot import name get_path_info

Try setting dj-static==0.0.6 in your requirements.txt file for Virtualenv. There might be a versioning issue on PyPI or a Django1.7 issue or the Heroku tutorial shows to use 0.0.5.
I've reported this issue to Heroku and their tutorial is now updated to reflect newer versions in the requirements.txt.

Related

Adding whitenoise to django gives an "ImproperlyConfigured: WSGI application" error

My application works if I were not to add
"whitenoise.middleware.WhiteNoiseMiddleware"
into the MIDDLEWARE in settings.py
but if I were to add it back, then it would not work and would give this error
django.core.exceptions.ImproperlyConfigured: WSGI application 'story_4.wsgi.application' could not be loaded; Error importing module.
This is what is inside my wsgi.py file
#wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'story_4.settings')
application = get_wsgi_application()
Any answer is appreciated.
Problem solved, Please remember to update your Whitenoise to the latest version with pip install --upgrade whitenoise
Mine was still at 3.3.0 and apparently django didn't like it.

ModuleNotFoundError: No module named 'django' while running manage.py

I have installed virtualenv and then installed django in my Windows 10. After activating virtualenv and running: python manage.py runserver, I am getting:
File "manage.py", line 10, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
ImportError: Couldn't import Django. Are you sure it's installed and available
on your PYTHONPATH environment variable? Did you forget to activate a virtual
environment?
Also just found while running django-admin.exe I am getting:
Note that only Django core commands are listed as settings are not properly
configured (error: Requested setting INSTALLED_APPS, but settings are not
configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing
settings.).
Manage.py:
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wordcount.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
You can verify whether you have installed django by creating a python program and importing django
import django
print (django.VERSION)
Above code will print the django version installed , confirm whether you have installed django
You have 2 Python versions : The main one which is installed by default and the one used by virtualenv.
When you run pip install django Django is installed in the main version of Python and thats because the PYTHONPATH environment variable refers to path of the main version and not virtualenv.
The same thing happens when you run python manage.py runserver. It doesn't run python from the virtualenv.
To solve this you need to access pip from the virtualenv and then you can insall Django with it
C:\the\path\to\virtualenv\path\to\pip.exe install django
And just like pip, run python.exe from virtualenv
C:\the\path\to\virtualenv\path\to\python.exe manage.py runserver
If you are using PyCharm for development then you can easily set your venv as interpreter.
Now to run django and just like pip you will access python from virtualenv
1 - File > Settings > Your Project > Python Interpreter
2 - Click the settings icon at the right and then click on Add
3 - Click on Virtualenv Environment and choose the location
Once the virtualenv has been setup you can easily use PyCharm to manage packages

ImportError: No module named django.core.wsgi

I am getting this error while deploying django project on uwsgi and nginx server
ImportError: No module named django.core.wsgi
Check Django Version
Make sure settings.py is loaded in to env properly.

how should i add python path in wsgi.py when using virtualenv

I am trying to deploy a django website using apache2.4, mod_wsgi on ubuntu 14.04.
The problem is that my wsgi.py file is unable to import django. this obviously means that i have not set python path for the virtualenv. But i am a little confused as to how to add python path of virtuaenv's site-packages.
my wsgi.py is:
import os
import sys
sys.path.append('/home/sp/webapps')
sys.path.append('/home/sp/webapps/ilog_dev')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ilog_dev.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
so the question is how should i add the virtualenv's site-package to python path
Have you tried path/to/virtualenv/activate before doing anything? Or maybe you didn't use virtualenv's python instead of global python.

Django WSGI and Gunicorn

This might be really stupid question; I'm trying to deploy Django application using Gunicorn. However, I just created wsgi.py which looks like below (wsgi.py is in my root project folder):
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
and now I ran:
python manage.py run_gunicorn
Will Gunicorn automatically picks up this wsgi.py? How does this work? (not sure what wsgi is doing). Or do i need to specify something?
If you have gunicorn listed in INSTALLED_APPS of Django settings module, the command is:
python manage.py run_gunicorn
Not the command you give.
I have Gunicorn to host my django site and this is the config details hope this is helpfull