Forums

Facing problem in setting up Django 1.7 in a different directory than root directory using virtualenv

Hi, I tried setting up a Django app in my production subdirectory but was unable to. It shows an error when I try to access the page. I also edited wsgi file to the production subfolder's Django app. This also did not work. However, if I create a custom app in root directory, it works (The way done in pythonanywhere tutorial.)

The name of my virtualenv is 'django17'. My Django app is called 'pricinfix'. In setting up my virtualenv, I followed pythonanywhere's tutorial but deviated from it by creating django app in 'production' subdirectory. After this, I am unable to setup my environment. I am noob in django and virtualenv. So, any help is welcome.

Can I take a look at your files? (We can see them from our side, but we always ask permission before looking.)

Sure

The log is showing the error message :

Internal Server Error: / Traceback (most recent call last): File "/home/astitwlathe/.virtualenvs/django17/lib/python3.4/site-packages/django/core/urlresolvers.py", line 364, in urlconf_module return self._urlconf_module AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module

What happens if you start a bash console in the virtualenv (there should be a link just underneath the virtualenv field on the "Web" tab, then go to your web app's directory and run python3.4 manage.py shell?

It is opening up the shell when I go to /home/astitwlathe/production/pricinfix.

I was browsing through https://www.pythonanywhere.com/forums/topic/1278/. I am also using python 3.4. and installed everything using this version.

Ah, got it, I should have recognised this error. In your WSGI file, where you have this:

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

...you need to replace it with this:

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Where did you get the WSGI file from? The code you had is valid for Django 1.3-1.6, but not for 1.7. Our instructions should make that clear, but perhaps we've missed some out.

I created Django app a lot of times to debug the problem. One of them was in root directory. So, I copied the wsgi settings from that Django 1.7 app as that was working fine. I think it also got created over Django 1.6 since till yesterday I was trying out the default django app provided on pythonanywhere.

Thanks for your help. I would not have been able to solve this issue on my own.

Is it all working OK now?

Thanks for the explanation of where you got the WSGI file from -- that makes sense. Because our Django "quickstart" only handles 1.3 or 1.6, then its default WSGI file uses the old-style application code. I'll modified it so that it has this at the bottom by default so that other people don't get caught out:

## If you're modifying this file to use Django 1.7 or higher, use the following
## instead of the two lines above:
# from django.core.wsgi import get_wsgi_application
# application = get_wsgi_application()

[edit: the extra comment will go live when we next update PythonAnywhere, so it's not there right now.]

Yes, I think more or less, I have to try it out a bit ...

Hi i am kinda having the same problem or maybe little different :

everything works fine up until I hook up the viritual env

after that my page is loading forever and not display anything at the end i get the error : to many redirects

when I remove the virtual env and hook up the source code for my up in the wsgi it works all fine

Solved the problem - i think I wasn't setting the python version properly in my environment followed new virtual env guide and sorted