Apache server does not connect to Django - python

So, I'm running Apache2 on a Linux machine, and I'm trying to serve pages with Django 1.3. I found a guide to do this here.
I have the django.wsgi configured, the settings.py configured, and the database created and successfully in sync with Django. However, when I try to visit the website, I am shown a page served by Apache, instead of Django. I get no errors/warnings at all.
I put print statements in both django.wsgi and settings.py (since they're both just python files), but nothing gets printed.
Does anyone have any idea as to what may be going wrong or any diagnostic steps I might be able to take?
Thanks!

As everyone has said in the comments, you need to add a WSGIServerAlias directive to the Apache configuration before anything will work. Otherwise, Apache can't possibly know to use WSGI to serve your site.

Related

Configuring mod_wsgi for Django?

I have configure mod_wsgi along with Apache 2 and tested with my Debain Squeeze 6. I need to put my code under /var/www directory as a extension .wsgi.
Now, I want to configure Django with mod_wsgi. How do I do it? Do I put my every files under /var/www. Is there a security issue or something? Can someone tell me step by step to configure django with mod_wsgi and where would be better to put the DJango codes? Thank you! P.S I have intermediate Django knowledge.
Here are a couple of links that you can use. The first one has proven the most useful for me as it is very detailed!
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
https://code.djangoproject.com/wiki/django_apache_and_mod_wsgi
Hope it helps!
EDIT:
Regarding security, as long as you provide access to the apache user (or www-data, depending on your linux distribution) (chown and chgrp) for all files in your /var/www/html/your_django_project you should not have any issues. Do NOT run anything as superuser.
Be careful to allow the apache user to write your log files, wherever they are. You could get irrelevant errors which could be caused by that.
Also, setup apache to serve django media files if you don't want to end up with media-less pages :-)
There's a pretty good instruction set on the documentation site.

Deploying Django using fcgi causes slow page loading

I need to deploy my django app on a shared server, where I don't have root access (e.g. httpd.conf) andn all I have is the folder public_html.
Now, I followed the sites describing using fcgi to deploy django (e.g. this). However, the pages load very slowly, I guess the reason is that django needs to be reloaded upon every request? Essentially, I would like a server that runs permanently and simply gets requests from apache.
Before trying out the solution with sockets and so on, I would like to ask for some professional opinions.
thanks!
FCGI sucks. Even its author admits it.
Using Apache ? Try mod_wsgi. It's the most professional deployment solution for apache.
Using Nginx or something else ? Then consider uWSGI. or gunicorn.
Link to a benchmark.

How do I initialise my Satchmo website?

As an experienced PHP programmer I tend to avoid things like Python. However we all must play with the cards we have been dealt with and I now have to work with a Satchmo website.
I have very little python, django and satchmo so I need some help. I'm ok with setting up a development server but I cannot get my website to work on a production server.
I've seen the use of "python manage.py runserver", this solution is even on Stack Overflow. However, when I see this solution there is usually someone saying "I hope you're not using that on production" so I assume this is a very incorrect way to do it. To my frustration the people that seem to know that this command line is insecure, also have no desire to share with the rest of us, just how excatly does one initiate their Satchmo Production server?
Many thanks.
To deploy a Django website on a production server, you have to serve it either with Apache+mod_wsgi, nginx+gunicorn, nginx+uwsgi, or any other server supporting WSGI. The Django documentation has a page on deploying Django on Apache with mod_wsgi, for the other solutions, there are plenty of useful documentation around the web.
runserver is just for development/testing. It won't handle high load, security, etc.
Python.org has docs on how to set up a proper webserver to serve Python code:
http://docs.python.org/howto/webservers.html
Satchmo seems like a django derivative. Setting up django on production is quite easy if your deployment environment is linux with apache then use mod_wsgi which is well documented here if its windows then you can use the pyisapie module and follow the documentation here
Hope that helps

Django Internal Server Error

I'm new at this and stuck. What would cause Django to run without error when I do python manage.py runserver but then throw Internal Server Error when I try to access it through the web? I have another project giving the Congratulations on your first Django-powered page, and I got the same result with the same .wsgi file initially with this project.
It wasn't until I tried to install this script in massivecoupon project that I got Internal Server Error:
http://github.com/coulix/Massive-Coupon---Open-source-groupon-clone
UPDATE:
I set Debug to True in settings.py and now I am getting the django error:
ViewDoesNotExist at /
Could not import massivecoupon.engine.views. Error was: No module named libs
You can use in command line
[user]$ python manage.py check
Regards
Quick answer: check your apache/tomcat access.log and error.log
Next, the other (not really dup) question I quoted above may be a different situation, but I recommend looking into the same things:
Your PYTHONPATH may not contain your project directory, or your DJANGO_SETTINGS_MODULE may not contain 'mysite.website', at least from apache's point of view. Whatever user apache runs as for your website needs to have that set up for it, like in its .profile. Or if you're using mod_python, they need to be set up in the .htaccess or apache's httpd.conf. Or if you're using mod_wsgi, it needs to be in the wsgi setup file -- passenger_wsgi.py or the like -- whatever apache's module will be looking for.
Next:
check if the files it needs to access are accessible by what apache runs your django site as
make sure your database is accessible by that user
and that the database setup/password is accessible by that user
make sure you have SITE_ID=1 set
make sure that you have a site record added into the database
First off check the Apache error log. If there is nothing in Apache error log, due to it being an internal error to your code or Django while handling a request, set DEBUG to True in Django site settings file and restart Apache so details of error display in the browser.

Apache/Django freezing after a few requests

I'm running Django through mod_wsgi and Apache (2.2.8) on Ubuntu 8.04.
I've been running Django on this setup for about 6 months without any problems. Yesterday, I moved my database (postgres 8.3) to its own server, and my Django site started refusing to load (the browser spinner would just keep spinning).
It works for about 10 mintues, then just stops. Apache is still able to serve static files. Just nothing through Django.
I've checked the apache error logs, and I don't see any entries that could be related. I'm not sure if this is a WSGI, Django, Apache, or Postgres issue?
Any ideas?
Thanks for your help!
It sounds a lot like there's something happening between django and your newly housed database.
Just to eliminate apache from the mix, you should run it as the dev server (on some random port to stop people using it) and see if you still have issues. If you do, it's the database. If it behaves, it could be apache.
Edit, This looks interesting. You can test that by applying his patch (commenting out the .close()) but there are other similar bugs floating around.
Found it! I'm using eventlet in some other code and I imported one of my modules into a django model. So eventlet was taking over and putting everything to "sleep".

Categories