Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:25:55+00:00 2026-06-11T07:25:55+00:00

Trying to deploy a Django 1.4 project using mod_wsgi and virtualenv, i’m running into

  • 0

Trying to deploy a Django 1.4 project using mod_wsgi and virtualenv, i’m running into a 500. The Apache error_log reveals:

mod_wsgi (pid=30452): Exception occurred processing WSGI script '/path/to/project/site-packages/projectapp/wsgi.py'.
[...] Traceback (most recent call last):
[...]   File "/path/to/project/env/myenv/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 219, in __call__
[...]     self.load_middleware()
[...]   File "/path/to/project/env/myenv/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[...]     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[...] ImproperlyConfigured: Error importing middleware projectapp.content.middleware: "cannot import name SomeModel"

From the error message i would expect that this is some kind of a path issue. However, when the offending middleware is removed from the Django settings, the site launches just fine, and there are other modules loaded from projectapp.content, SomeModel is also loaded in this case, otherwise the whole site wouldn’t be able to run.

The import error raised doesn’t come directly from the middleware, as it doesn’t import the model. SomeModel is defined in a speparate app which is actually checked out into the src directory of the virtualenv. But the directory containing this app is also in the path.

The wsgi.py file i’m using:

import os
import sys

sys.stdout = sys.stderr

sys.path.insert(0, '/path/to/project/env/myenv/lib/python2.6/site-packages/')
# The module inside the following directory
# defines SomeModel from the error message
sys.path.insert(0, '/path/to/project/env/myenv/src/some-app/')
sys.path.insert(0, '/path/to/project/site-packages/')

import django.core.handlers.wsgi

os.environ['DJANGO_SETTINGS_MODULE'] = 'projectapp.settings'
application = django.core.handlers.wsgi.WSGIHandler()

Printing sys.path after inserting the module paths shows everything in the expected order, /path/to/project/site-packages/ is listed first and /path/to/project/env/myenv/src/some-app/ (which defines SomeModel) second.

I’ve also tried a different variant, based on the example from the mod_wsgi docs:

import os
import sys
import site

ALLDIRS = [
    '/path/to/project/site-packages/',
    '/path/to/project/env/myenv/lib/python2.6/site-packages/',
    '/path/to/project/env/myenv/src/some-app/',
]

# Remember original sys.path
prev_sys_path = list(sys.path)

sys.stdout = sys.stderr

# Add each new site-packages directory
for directory in ALLDIRS:
    site.addsitedir(directory)

# Reorder sys.path so new directories are at the front
new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:
        new_sys_path.append(item)
        sys.path.remove(item)
sys.path[:0] = new_sys_path

#activate_this = '/path/to/project/env/myenv/bin/activate_this.py'
#execfile(activate_this, dict(__file__=activate_this))

import django.core.handlers.wsgi

os.environ['DJANGO_SETTINGS_MODULE'] = 'projectapp.settings'
application = django.core.handlers.wsgi.WSGIHandler()

The error logged by Apache is exactly the same.

I have to add that the middleware is loaded just fine when i’m running the development server on the same machine, so i have no idea what’s going wrong. Is there a way to get a better traceback from mod_wsgi?

EDIT:

Fogot to mention that i’m using mod_wsgi in daemon mode. Here are the relevant parts from my vhost config:

<VirtualHost x.x.x.x:80>
    WSGIDaemonProcess foo user=foo threads=10 umask=0002
    WSGIProcessGroup foo
    WSGIScriptAlias / /path/to/project/site-packages/projectapp/wsgi.py
</VirtualHost>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:25:56+00:00Added an answer on June 11, 2026 at 7:25 am

    Okay after hours of debugging this turned out to be a race condition caused by the middleware. The middleware i’m using is similiar to the FlatpageFallbackMiddleware from Django contrib and actually the import of the view caused the problem.

    from projectapp.content.views import generic_content_detail
    class ContentFallbackMiddleware(object):
        def process_response(self, request, response):
            [...]
    

    Moving the import statement inside the process_response method solved the problem for me:

    class ContentFallbackMiddleware(object):
        def process_response(self, request, response):
            from projectapp.content.views import generic_content_detail
            [...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to deploy my django project on a shared hosting as describe here
I have been trying to integrate Google calendar into a Django application running on
When trying to deploy a VS2010 database project using the VSDBCMD tool, I get
I'm trying do deploy a django project. I tried a lot of tutorials, but
I'm trying to deploy a django application for production on apache mod-wsgi. I have
I'm trying to deploy my Django application on my linode server with apache and
Trying to deploy application using ClickOnce to a webserver running sharepoint. I can publish
I'm trying to deploy django using wsgi . But its not working. Will you
I'm trying to deploy a django project via mod_python and I keep getting an
I'm trying to deploy a small django app on Heoroku using the documentation provided.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.