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.
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.
So I've been working on my first Django / Python project and I got my production server up and running. I was wondering if it's possible to make Python/FastCGI (not really sure which is responsible for the task) to recompile my code. As of right now, when I upload updated code, I need to restart the server for the changes to take place. I read that you can add some kind of mysite.fcgi file to lighttpd so it see's that you've updated the code, can you do the same for Nginx / FastCGI?
for anyone else that was interested in my question.. this is only a partial solution, but I ended up finding my answer here: How to gracefully restart django running fcgi behind nginx?
You can just run the script (I'm going to modify it a bit), everytime you edit your code and it will gracefully restart everything without dropping connections.
This is a general guide from the mod_wsgi project that outlines how you can monitor code changes from your app_wsgi.py and restart the current process if any of the modules have changed. You need to restart the Python process, because threads contending over modules could mean that a freshly reloaded module has outdated references from other modules that are still waiting to get discovered for reload.
If you want something that works nicely with nginx, Django and wsgi apps in general, take a peek at Spawning as your wsgi server. It's approach to code reloading is about as graceful as it gets.
It has great documentation, well documented request handling model and it just works, which makes it such a no-brainer to configure. You'd need less than five minutes from now to having your Django instance running on Spawning. Here's another topical blog to get your juices running.
I'm working with web2py and for some reason web2py seems to fail to notice when code has changed in certain cases. I can't really narrow it down, but from time to time changes in the code are not reflected, web2py obviously has the old version cached somewhere.
The only thing that helps is quitting web2py and restarting it (i'm using the internal server).
Any hints ? Thank you !
web2py does cache your code, except for Google App Engine (for speed). That is not the problem. If you you edit code in models, views or controllers, you see the effect immediately.
The problem may be modules; if you edit code in modules you will not see the effect immediately, unless you import them with local_import('module', reload=True), or by restarting web2py.
Is that is also not your problem, then your browser is caching something. Please bring up this question to the web2py mailing list as we can help more.
P.S. If you are using the latest web2py it no longer comes with cherrypy. The built-in web server is called Rocket.
web2py itself shouldn't "cache" your code, but whatever app server you're using it on surely might. But web2py can be deployed on such a huge variety of app servers that it's impossible to give completely general suggestions.
If you're using the popular cherrypy WSGI server that I believe comes bundled with web2py, for example, see, in cherrypy's own docs, the AutoReload feature. Such features are not recommended in a production deployment (they can require very significant resources), but they sure come in handy when you're just developing!-)
I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.
I start the server using
python manage.py testserver
I can see each GET request (PNGs and style sheets) take about half a second.
Another weird thing, which I think is related, is that the functional tests for the app run much slower on my machine with MySQL (on order of 100 times slower than on my colleague's machine). When I set the app to use sqlite, they run pretty quickly. I would like to exclaim that sqlite doesn't much change the time it takes to load a page, but it does speed up server startup.
It looks like IO problem, but I don't see general performance problems on my machine, apart from django at least.
Django runs on python2.4, I'm running Vista. I have also checked python2.5.
Thanks ΤΖΩΤΖΙΟΥ, It must totaly be a DNS problem, because the page loads up quickly as soon as
instead of http://localhost:8000/app I go to http://127.0.0.1:8000/app.
But what could it be caused by? My host file has only two entries:
127.0.0.1 localhost
::1 localhost
Firefox has a problem browsing to localhost on some Windows machines. You can solve it by switching off ipv6, which isn't really recommended. Using 127.0.0.1 directly is another way round the problem.
None of these posts helped me. In my specific case, Justin Carmony gave me the answer.
Problem
I was mapping [hostname].local to 127.0.0.1 in my /etc/hosts file for easy development purposes and dns requests were taking 5 seconds at to resolve. Sometimes they would resolve quickly, other times they wouldn't.
Solution
Apple is using .local to do some bonjour magic on newer Snow Leopard builds (I think i started noticing it after updating to 10.6.8) and Mac OS X Lion. If you change your dev hostname to start with local instead of end with local you should be all set. Additionally, you can pretty much use any TLD besides local and it will work without conflict.
Example
test.local could become:
local.test.com
test.dev
test.[anything but local]
and your hosts file entry would read:
local.test.com 127.0.0.1
Note: This solution has the added benefit of being a subdomain of [hostname].com which makes it easier to specify an app domain name for Facebook APIs, etc.
Might also want to run dscacheutil -flushcache in the terminal for good measure after you update /etc/hosts
I have had the same problem in the past. It can be solved by removing the following line from your hosts file.
::1 localhost
Once that's gone you should be able to use localhost again, quickly.
Since you report your friend's machine has no delays, and I assume yours and his are comparable computers, it could be a DNS related issue. Try to add both the client's and the server's IP address to the server's hosts file.
If you run Django on *nix, it's the /etc/hosts file. If run it on MS Windows, it's the %WINDIR%\SYSTEM32\DRIVERS\ETC\HOSTS file. (They are text files and can be edited by your favourite text editor.)
I think it's the development server, it's not optimized for speed nor security. I noticed that specially serving static files (i.e. media) is slow.
And if all else fails, you can always cProfile your application and see where exactly is the bottleneck.
Had the same problem too, I've noticed it with Firefox on Vista and Windows 7 machines. Accessing the development server 127.0.0.1:8000 solved the problem.
Upgrade to Django 1.3 or newer.
If you still have this problem in 2012 (using Chrome), make sure you're upgrading. In 1.3, a bug was fixed related to slowness when the dev server was single threaded.
Upgrading solved my issues. I was running Django 1.2 since that's the default on Debian Squeeze.
I had the same problem but it was caused by mysqld.
The app worked pretty fast on production with wsgi and a mysql server in the same host but slow in the development environtment with the django runserver option and a remote mysql server.
I noticed using "show processlist" that connections in database where stuck in the state "login" with user "unauthenticated user" and this make me notice that the problem where in the authentication process.
Looking for the real problem, I finally noticed that mysqld was trying to get the dns name of my ip and disabling the name dns resolution, I fixed the problem.
To do that, you can add this line into my.cnf file:
skip-name-resolve
I solved this issue like this:
go to setting.py and set
DEBUG = False
Disable AV Scanning & see if that makes a difference. It could also be caused by Vista. Upgrade to the latest service pack and try again.
To completely bypass localhost without altering the hosts file or any settings in Firefox you can install the addon Redirector and make a rule to redirect from localhost to 127.0.0.1. Use these settings
Include pattern : http://localhost*
Redirect to : http://127.0.0.1$1
Leave the other fields empty.
i got the same problem.
the solution was :
I was trying to start localy a version that was usualy deployed on a webserver in production.
The static files in production were served by an apache config and not with django static serve
so I just uncommented back my static serve urls :/
Slow Loading of Static Files
If you notice that static and media files (images, style sheets, etc.) are particularly slow to load, the problem might be Django's development server (python manage.py runserver). As noted by hassen, that server is not optimized for speed.
You can try using django-extensions runserver_plus command with the --threaded option as a replacement for Django's runserver command. Under the hood, it uses Werkzeug as the threaded WSGI server. You may notice a huge improvement in loading times for static files.
Also see: Making Django development server faster at serving static media
For me it was Django Debug Toolbar - its amazingly helpful when its needed but when it isn't it can slow development down which can be extremely frustrating and hard to identify. I find its better to disable it during development unless you need it. :zombies-never-die: