1
votes

I have a simple admin django project and there I created another application called webadmin. Project structure is as follow:

  • tstprj
    • manage.py
    • tstprj
      • settings.py
      • urls.py
      • wsgi.py
      • init.py
    • webadmin
      • admin.py
      • urls.py
      • views.py
      • models.py
      • init.py

I have a separate wsgi file that I reference from apache conf:

# tstprj.wsgi
import os
import sys
sys.path.insert(0, '/var/www/tstprj')

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

and apache's virtual host - tstprj.conf:

<VirtualHost *:80>
WSGIScriptAlias / /home/pm/dev/tstprj.wsgi

ServerName <<my_ip_address>>

Alias /static /var/www/tstprj/static/

<Directory /var/www/tstprj/>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

I get the error ImportError at / No module named urls. The traceback:


    Environment:


    Request Method: GET
    Request URL: http://<<my_ip_address>>/

    Django Version: 1.6
    Python Version: 2.7.3
    Installed Applications:
    ('django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'webadmin')
    Installed Middleware:
    ('django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware')


    Traceback:
    File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
      101.                 resolver_match = resolver.resolve(request.path_info)
    File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
      318.             for pattern in self.url_patterns:
    File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
      346.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
      341.             self._urlconf_module = import_module(self.urlconf_name)
    File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
      40.         __import__(name)
    File "/var/www/tstprj/tstprj/urls.py" in 
      11.     url(r'^admin/webadmin', include('webadmin.urls')),
    File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
      26.         urlconf_module = import_module(urlconf_module)
    File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
      40.         __import__(name)

    Exception Type: ImportError at /
    Exception Value: No module named urls

And, of course, tstprj.urls:


    from django.conf.urls import patterns, include, url

    from django.contrib import admin
    admin.autodiscover()

    urlpatterns = patterns('',

        url(r'^admin/webadmin', include('webadmin.urls')),
        url(r'^admin/', include(admin.site.urls)),
    )

EDIT: webadmin.urls

from django.conf.urls import *
from webadmin.views import *

urlpatterns = patterns('',  
    url(r'^/playlist/(?P<plid>(\d+))/song/add/$', addSong, name="addsong"),
    url(r'^/playlist/(?P<plid>(\d+))/song/(?P<sgid>(\d+))/delete/$', deleteSong),
    url(r'^/playlist/(?P<plid>(\d+))/up/$', moveUpSong),
    url(r'^/playlist/(?P<plid>(\d+))/down/$', moveDownSong),
    url(r'^/playlist/(?P<plid>(\d+))/top/$', moveTopSong),
    url(r'^/playlist/(?P<plid>(\d+))/bottom/$', moveBottomSong),
    url(r'^/playlist/(?P<plid>(\d+))/position/$', moveToPositionSong),
    url(r'^/playlist/(?P<plid>(\d+))/deleteSelected/$', deleteSelectedSongs),
    url(r'^/user/(?P<uid>(\d+))/deleteSelected/$', deleteSelectedStations), 
    url(r'^/user/(?P<uid>(\d+))/station/(?P<sid>(\d+))/playlist/deleteSelected/$', deleteSelectedPlaylists),
    url(r'^/user/(?P<uid>(\d+))/station/(?P<sid>(\d+))/playlist/(?P<plid>(\d+))/delete/$', deletePlaylist),
    url(r'^/user/(?P<uid>(\d+))/station/(?P<sid>(\d+))/playlist/add/$', addPlaylist, name="addplaylist"),   
    url(r'^/user/(?P<uid>(\d+))/playlist/all/$', playlist_list, name="playlist_list"),  
    url(r'^/user/(?P<uid>(\d+))/station/add/$', addStation, name="addStation"),
    url(r'^/user/(?P<uid>(\d+))/station/(?P<sid>(\d+))/$', viewStation, name="viewStation"),
    url(r'^/user/(?P<uid>(\d+))/station/(?P<sid>(\d+))/delete/$', deleteStation, name="deleteStation"), 
)

What is the matter?

2
Also, did you installed webadmin in INSTALLED_APPS?Jorge Leitao
@Yogesh added to question. In development everything runs ok.Mike Spike
@J.C.Leitão yes I did if that's in the settings.py file(I'm new to django and web development)Mike Spike
What is the content of tstprj.wsgi?manu
it's the first block of codeMike Spike

2 Answers

0
votes

I'm not sure, but your apache configuration may be incomplete. I'm unsure the python version it calls is the one you want.

I normally set the python path, like this:

WSGIDaemonProcess process_name processes=2 threads=12 python-path=/home/pm/dev:home/pm/.../lib/python2.7
WSGIProcessGroup process_name
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIScriptAlias / /home/pm/dev/tstprj.wsgi

The first line ensures that Python uses the libraries installed in "home/pm/.../lib/python2.7", and is able to reach "/home/pm/dev".

I'm unsure this answers this question, but maybe you can try it.

0
votes

Of course you don't want this answer anymore! but:
Add project and App dirs to sys.path in wsgi.py of your project and it may find all of the modules in your project

import sys
sys.path.append('<Project_Directory>')
sys.path.append('<Project_Directory>/AppName')