0


Am in a problem when deoply my django web app to local apache server,its worked in Development server. My project name is 'DjangoApis' project's structure : home/ji/Desktop/testcloud/DjangoApis/

__init__.py
  django.wsgi
  settings.py
  manage.py
  urls.py 
  mywebapp
       --> __init__.py
       --> static
       --> templates
       --> urls.py
       --> views.py
  myapis ( create it as a project itself)
       --> __init__.py
       --> manage.py
       --->....

settings.py:

INSTALLED_APPS = (        
    'DjangoApis.mywebapp',
    'DjangoApis.myapis',
)

django.wsgi:

**

import os
import sys
path = '/home/ji/Desktop/testcloud.aws'
if path not in sys.path:
    sys.path.append(path)   
os.environ['DJANGO_SETTINGS_MODULE'] = 'DjangoApis.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

**

urls.py in Project folder(DjangoApis):

urlpatterns = patterns('',   

    url(r'^admin/', include(admin.site.urls)),
)
urlpatterns = patterns('',
  (r'^api/', include('DjangoApis.myapis.url')),
  (r'^', include('DjangoApis.mywebapp.urls')),      
)

/etc/apache2/sites-enabled

 VirtualHost *:80
        ServerName test.webapp
        DocumentRoot /home/ji/Desktop/testcloud/DjangoApis

        <Directory /home/ji/Desktop/testcloud/DjangoApis>
            Order allow,deny
            Allow from all
        </Directory> 
        WSGIDaemonProcess test.webapp processes=2 threads=15 display-name=%{GROUP}
        WSGIProcessGroup test.webapp 
        WSGIScriptAlias / /home/ji/Desktop/testcloud/DjangoApis/django.wsgi

    /VirtualHost

when I run in browser< I got Internal Server Error.
error log:

tail /var/log/apache2/error.log
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]     default_translation = _fetch(settings.LANGUAGE_CODE)
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]   File "/usr/lib/pymodules/python2.7/django/utils/translation/trans_real.py", line 162, in _fetch
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]     app = import_module(appname)
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]   File "/usr/lib/pymodules/python2.7/django/utils/importlib.py", line 35, in import_module
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]     __import__(name)

[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1] TemplateSyntaxError: Caught ImportError while rendering: No module named myapis

[Thu Dec 08 17:56:46 2011] [notice] SIGUSR1 received.  Doing graceful restart
[Thu Dec 08 17:56:46 2011] [warn] mod_wsgi: Compiled for Python/2.7.2rc1.
[Thu Dec 08 17:56:46 2011] [warn] mod_wsgi: Runtime using Python/2.7.2+.
[Thu Dec 08 17:56:46 2011] [notice] Apache/2.2.20 (Ubuntu) mod_wsgi/3.3 Python/2.7.2+ configured -- resuming normal operations

Note: Am using django piston.Please help me to rectify the problem,Thanks in advance.

Jisson
  • 3,566
  • 8
  • 38
  • 71
  • Try to: 1) add manage.py to project directory 2) use full path to your apps - DjangoApis.mywebapp, DjangoApis.myapis – SkyFox Dec 08 '11 at 14:11
  • @skyfox manage.py already there am sorry to specify that,I tried DjangoApis.mywebapp, DjangoApis.myapis,it also not working,Now I got the Django default error page with message,ImportError at / No module named mywebapp.urls,[previously I got apache's error page(I think )] And also Iadded improt mywebapp to project's urls.py file – Jisson Dec 08 '11 at 14:26
  • apache error log has no any indication of error – Jisson Dec 08 '11 at 14:31

1 Answers1

0

Add:

sys.path.append('/home/ji/Desktop/testcloud.aws/DjangoApis')

That you need to add both parent directory and project directory is documented in:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • I edited django.wsgi as you suggested,But I don't know am still facing the problem. If I comment the line (r'^', include('mywebapp.urls')), in Project's urls.py there is no error.Also I added import DjangoApis.mywebapp in the file – Jisson Dec 09 '11 at 05:46
  • Is myapis directory actually readable to user that your application runs as under Apache. – Graham Dumpleton Dec 09 '11 at 06:20
  • Yea myapis readable and its runs under apache, Now shows the error 'ImportError at / No module named mywebapp' – Jisson Dec 09 '11 at 07:10
  • what is the correct way to import an app's url in project? url(r'^appurl',include(project.app.urls)) is it correct? import project.app or from project.app import urls which one is the correct way? – Jisson Dec 09 '11 at 07:21
  • Not only adding sys.path.append('/home/ji/Desktop/testcloud.aws/DjangoApis') solves the problem. Use as below import DjangoApis.mywebapp from DjangoApis.mywebapp.urls import * (r'^', include('project.app.urls')),[also add 'projectname.app' in installed apps in settings file ] – Jisson Dec 09 '11 at 09:09
  • Thanks @Graham Dumpleton,now mysite loading using mod_wsgi,Now I have a problem with my sttaic files,can you look the statckoverflow link and suggest what I am missing http://stackoverflow.com/q/8456083/658976 – Jisson Dec 12 '11 at 06:01
  • now django tries to load /home/jisson/Desktop/testcloud.aws/DjangoApis/staticjs, instead of /home/jisson/Desktop/testcloud.aws/DjangoApis/static/js – Jisson Dec 12 '11 at 06:05