Django plugged into Apache not working like Django standalone

2024/10/15 17:23:20

I have encountered a hodgepodge of errors trying to bring my django site into production with Apache. Having finally gotten mod_wsgi sorted and Apache at least seeming to be trying to load the site I'm seeing a number of confusing problems in the debug details when the homepage fails to load.

None of these errors emerge when I fire up the site using python manage.py runserver 10.10.10.214:8080 - it works 100% fine that way

  1. Import errors - I cannot from x import y - for some reason it will only allow me to do from x import * An example was #from django.conf.urls import patterns, include, url gave an error - I had to change to from django.conf.urls.defaults import *
  2. Permission errors - for example, I had to chmod the DB file which worked fine before. No big deal I suppose but I just wondered why
  3. DB field errors: Cannot resolve keyword 'user_id' into field. Choices are: end_date, id, singleDate, start_date, user user_id worked just fine in standalone mode.
  4. Apache log was giving errors like TemplateSyntaxError: Caught ImportError while rendering: No module named staticfiles which I just lazily bypassed by commenting out django.contrib.staticfiles in settings.py. This solved nothing, needless to say

It almost felt like the files were being handled on a standalone basis and not within the django framework. Has anyone experienced these kind of teething problems before? I was foolishly thinking I could just plug in. I have a (unfounded) optimistic feeling it must just be a directive in some file.

Cheers, Arthur

Answer

Are you sure the target system has the same version of Django installed?

Is the mod_wsgi even compiled for the version of Python you want to use? It is a common mistake that people don't realise that mod_wsgi is actually for a different Python version and so not using the same Python installation as you expect and therefore using different versions of packages.

As to the permissions errors, this is because the code when run under Apache is running as the Apache user by default. It will not have access rights the same as you do when run manually. You also have to be careful on making assumptions about what the working directory of the process is.

  • https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Access_Rights_Of_Apache_User
  • https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_Working_Directory

In order to try and sort out things out, you may be better to try and use mod_wsgi-express in your development environment. This way development environment is closer to your target system.

  • http://blog.dscpl.com.au/2015/04/integrating-modwsgi-express-as-django.html
  • http://blog.dscpl.com.au/2015/04/using-modwsgi-express-with-django.html
  • http://blog.dscpl.com.au/2015/05/using-modwsgi-express-as-development.html
https://en.xdnf.cn/q/117808.html

Related Q&A

How to filter overlap rows in a big file in python

I am trying to filter overlap rows in a big file in python.The overlap degrees is set to 25%. In other words,the number of element of intersection between any two rows is less than 0.25 times of union …

Installing wxPython in Ubuntu 12.10

I am trying to install wxPython on my Ubuntu 12.10 but with no success. I have gone through all the answers given on this website. Can someone please help me in this or point me in the right direction.…

Open a file name +date as csv in Python [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

TextCtrl providing an out of bound exception in wxPython

I am new to WX, so I decided to make a program that will periodically write out a line of text to the screen based on an outside input. The basis of the program contains a basic window with the multili…

Matplotlib: different color for every point of line plot

Im trying to make a plot like in the following figure (source of image): Im talking about the plot in the right panel even though there is some correlation between the two panels: the colorbar. Just s…

getting template syntax error in django template

my code in view :tracks = client.get(/tracks, order=hotness, limit=4) artwork_url=[] for track in tracks:artwork_url.append(str(track.artwork_url).replace("large", "t300x300")) …

Python threading:Is it okay to read/write multiple mutually exclusive parts of a file concurrently?

I know we can guarantee correctness either by locking or using a specialized thread whose sole job is to read/write and communicate with it through queue. But this approach seems logically ok, so I wan…

Theano Cost Function, TypeError: Unknown parameter type: class numpy.ndarray

Im new to Theano, just learning it. I have a ANN in python that Im implementing in Theano as learning process. Im using Spyder.And Theano throws out an error: TypeError: Unknown parameter type: class n…

Bar plotting grouped Pandas

I have a question regarding plotting grouped DataFrame data.The data looks like:data =index taste food0 good cheese 1 bad tomato 2 worse tomato 3 worse …

Nginx+bottle+uwsgi Server returning 404 on every request

I have setup an Nginx server with following configuration:server {listen 8080;server_name localhost;location / {include uwsgi_params;uwsgi_pass unix:/tmp/uwsgi.notesapi.socket;uwsgi_param UWSGI_PYHOME …