I'm trying to host a simple Django app on AWS.
I can run it via the public DNS and runserver, but I can't seem to get the environment URL working.
I checked the log and it says "ImportError: Could not import settings 'AppName.settings'"
I've tried adding sys.path.append('/opt/python/current/app/ProjectName/AppName') to the WSGI file, but when I try to print out the sys.paths, it is not listed.
How can I fix this?
Thanks!
I think you need to import till project name like
sys.path.append('/opt/python/current/app/ProjectName')
That will ensure project directory is in pythonpath and you can import AppName from there.
Related
I m new to django. I created a web with dajngo,and successfully deployed it in the server
The python app has been successfully setup and virtual environment has been setup.
but while running the web it gives me "Server Error (500)" I don't know whats the problem.
I think error is in "wsgi.py" file but i'm unable to idenify it.
My wsgi file:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'karan_web.settings')
application = get_wsgi_application()
my "passenger_wsgi.py" file is:
import imp
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
wsgi = imp.load_source('wsgi', 'karan_web/wsgi.py')
application = wsgi.application
can someone help me with it;
Sorry for the late answer, I had figured out the as to this just forgot to post it.
As I stated in my question, the actual problem was in passenger_wsgi.py, the django server starts with the wsgi.py and act as the gate way to the Django server.
So whenever a Django project is uploaded on the hosting server, It creates a passenger_wsgi.py file and one default wsgi.py, address of which is provided in passenger_wsgi.py by default.
So we just need to change that address and provide the address of our own wsgi.py in the project
In my case it was
import os
import sys
from karan_web import wsgi
application = wsgi.application
just edit in passenger_wsgi.py the following code.
from karan_web.wsgi import application
You need to check if your code syntax is correct and running properly. If its still doesn't work try to delete and recreate your database in cpanel and check if you have made all necessary migrations, don't forget to restart your python app. If after all these it still doesn't work check if all your files have the correct file permission(766).
I use django-haystack 2.0.0 to index my site, and it has been working great until I upgraded to Django 1.5 and started using the WSGI interface. If I just use the django_gunicorn command it works great, but the Django documentation "highly recommends" I use the gunicorn command.
When I start my site with the gunicorn command, Haystack throws the following error on any page load:
ImportError: cannot import name signals
I have no problems importing signals from the Django or Python shells. I use virtualenv and install all packages locally inside that environment. My wsgi.py file looks just like the default one in the django admin, except that I add the local path to the python path as such:
path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2])
if path not in sys.path:
sys.path.append(path)`
Any help you could provide would be very appreciated, thank you!
I don't use gunicorn, but I had the same problem when I used the HAYSTACK_SIGNAL_PROCESSOR setting to point to a custom class that I wrote. That class imported one of my models, which eventually propagated up the import chain, to import my settings module, thus causing a circular import.
When using a setting such as HAYSTACK_SIGNAL_PROCESSOR that points to a class, make sure that class standsalone, and doesn't import either directly or indirectly the Django settings file.
I am using django with mod_python (I know it is deprecated -- I am just doing this for an exercise), and am getting the following error --
"Could not import project.views. Error was: No module named app.models"
I am getting the 'No module named app.models" in several other places as well. My syncdb is working fine, and if I go into the manage.py shell I can import the models fine. Why is this occurring and what do I need to change? Thank you.
You should use absolute imports everywhere. If your project is structured like so:
/project/settings.py
/project/app/models.py
/project/app/views.py
In INSTALLED_APPS you would use project.app. In app you'd import your models into views: import project.app.models, etc. Alternately you can try adjusting your PYTHONPATH so your imports work. When you run ./manage.py you are in your project folder, and Python automatically adds it to the PYTHONPATH. This doesn't happen automatically in most deployment scenarios (mod_python or other wise).
So I have created a django site and I wanted to move it from my computer to my server. I set up Django on the server, and used the WSGI configuration. When I try to go to the home page I get an Import Error, It says that the module "myproject.urls" isn't found. It's a Django error, and it looks like it is getting the settings.py file and looking at the setting for ROOT_URLCONF and seeing the right urls file. I created this project with the usual django-admin.py startproject myproject and I just wanted to see if everything was configured correctly, but now I'm getting this error.
Any Suggestions?
Remove the "myproject" from "myproject.urls". Somehow WSGI addresses the settings as the root, so no need to refer to it again.
It sounds like myproject isn't on your path - what happens if you load up a python shell and run import myproject? If that works, what happens when you run import myproject.urls? If only the second import fails, there's a syntax error in your urls.py or one of the files it imports.
#Afrowave, you saved a huge headache - thank you from me too!
Further to this - I did a little more digging and wanted to avoid having to amend a dozen files in my app to account for loosing 'myproject.' and the start of every import.
Instead, I found if you do something like this -- you don't have to :)
ROOT = '/home/user/path_to_project_root' # In my case, also the dir that contains media, templates etc
APP_ROOT = '/home/user/path_to_django_project'
sys.path.append(ROOT)
sys.path.append(APP_ROOT)
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
Hope this helps someone in future.
I have a Django project that works fine with the development server that comes with it.
No errors are produced at all when I use "django manage.py runserver" and the app works fine, but when I try to use it with mod_wsgi and Apache the browser displays "Internal Server Error" with a 500 error code and it generates an import error in the Apache error log.
Here's the error in the log:
ImportError: No module named registration
I'm using the Django registration module which is located in a path like this:
/opt/raj/photos/registration
I know that the registration app is in the path because I can fire up a Python shell, import sys, and get a list of paths using sys.path.
Here are some of the paths output from Python shell:
sys.path
['', '/opt/raj/pyamf', '/opt/raj', '/opt/raj/pictures', '/opt/raj/pictures /registration', '/usr/lib/python2.6',....]
Any thoughts would be appreciated.
Is it in the pythonpath for the webserver? All those '/opt' paths are typically not in the standard python path, so something is adding those for you I would guess. Are you sure it also gets added for the webserver process, or is PYTHONPATH set in some shell configfile somewhere for your user only?
There is a PythonPath directive when using mod_python, is there something similar for mod_wsgi?
This is almost certainly a case of the path not being the same for the webserver as it is for you, so I would focus my search in those areas.