2010-03-28 14 views
11

Próbowałem uzyskać wniosek napisany w django działa - ale to nie działa w ogóle. Pracowałem też przez jakiś czas - i działa doskonale na serwerze dev. Ale nie jestem w stanie wprowadzić env produkcji (apahce).Django - brak modułu o nazwie app

Moja nazwa projektu to apstat, a nazwa aplikacji jest podstawowa.

próbuję uzyskać do niego dostęp, jak następuje

Blockquote http://hostname/apstat

Ale to pokazuje następujący błąd:

MOD_PYTHON ERROR 

ProcessId:  6002 
Interpreter: 'domU-12-31-39-06-DD-F4.compute-1.internal' 

ServerName:  'domU-12-31-39-06-DD-F4.compute-1.internal' 
DocumentRoot: '/home/ubuntu/server/' 

URI:   '/apstat/' 
Location:  '/apstat' 
Directory:  None 
Filename:  '/home/ubuntu/server/apstat/' 
PathInfo:  '' 

Phase:   'PythonHandler' 
Handler:  'django.core.handlers.modpython' 

Traceback (most recent call last): 

    File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch 
    default=default_handler, arg=req, silent=hlist.silent) 

    File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in _process_target 
    result = _execute_target(config, req, object, arg) 

    File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in _execute_target 
    result = object(arg) 

    File "/usr/lib/pymodules/python2.6/django/core/handlers/modpython.py", line 228, in handler 
    return ModPythonHandler()(req) 

    File "/usr/lib/pymodules/python2.6/django/core/handlers/modpython.py", line 201, in __call__ 
    response = self.get_response(request) 

    File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 134, in get_response 
    return self.handle_uncaught_exception(request, resolver, exc_info) 

    File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py", line 154, in handle_uncaught_exception 
    return debug.technical_500_response(request, *exc_info) 

    File "/usr/lib/pymodules/python2.6/django/views/debug.py", line 40, in technical_500_response 
    html = reporter.get_traceback_html() 

    File "/usr/lib/pymodules/python2.6/django/views/debug.py", line 114, in get_traceback_html 
    return t.render(c) 

    File "/usr/lib/pymodules/python2.6/django/template/__init__.py", line 178, in render 
    return self.nodelist.render(context) 

    File "/usr/lib/pymodules/python2.6/django/template/__init__.py", line 779, in render 
    bits.append(self.render_node(node, context)) 

    File "/usr/lib/pymodules/python2.6/django/template/debug.py", line 81, in render_node 
    raise wrapped 

TemplateSyntaxError: Caught an exception while rendering: No module named basic 

Original Traceback (most recent call last): 
    File "/usr/lib/pymodules/python2.6/django/template/debug.py", line 71, in render_node 
    result = node.render(context) 
    File "/usr/lib/pymodules/python2.6/django/template/debug.py", line 87, in render 
    output = force_unicode(self.filter_expression.resolve(context)) 
    File "/usr/lib/pymodules/python2.6/django/template/__init__.py", line 572, in resolve 
    new_obj = func(obj, *arg_vals) 
    File "/usr/lib/pymodules/python2.6/django/template/defaultfilters.py", line 687, in date 
    return format(value, arg) 
    File "/usr/lib/pymodules/python2.6/django/utils/dateformat.py", line 269, in format 
    return df.format(format_string) 
    File "/usr/lib/pymodules/python2.6/django/utils/dateformat.py", line 30, in format 
    pieces.append(force_unicode(getattr(self, piece)())) 
    File "/usr/lib/pymodules/python2.6/django/utils/dateformat.py", line 175, in r 
    return self.format('D, j M Y H:i:s O') 
    File "/usr/lib/pymodules/python2.6/django/utils/dateformat.py", line 30, in format 
    pieces.append(force_unicode(getattr(self, piece)())) 
    File "/usr/lib/pymodules/python2.6/django/utils/encoding.py", line 71, in force_unicode 
    s = unicode(s) 
    File "/usr/lib/pymodules/python2.6/django/utils/functional.py", line 201, in __unicode_cast 
    return self.__func(*self.__args, **self.__kw) 
    File "/usr/lib/pymodules/python2.6/django/utils/translation/__init__.py", line 62, in ugettext 
    return real_ugettext(message) 
    File "/usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py", line 286, in ugettext 
    return do_translate(message, 'ugettext') 
    File "/usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py", line 276, in do_translate 
    _default = translation(settings.LANGUAGE_CODE) 
    File "/usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py", line 194, in translation 
    default_translation = _fetch(settings.LANGUAGE_CODE) 
    File "/usr/lib/pymodules/python2.6/django/utils/translation/trans_real.py", line 180, in _fetch 
    app = import_module(appname) 
    File "/usr/lib/pymodules/python2.6/django/utils/importlib.py", line 35, in import_module 
    __import__(name) 
ImportError: No module named basic 

Moja settings.py jest następująca:

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'apstat.basic', 
    'django.contrib.admin', 
) 

Jeśli usunąć apstat.basic, przechodzi, ale to nie jest rozwiązanie. Czy to coś, co robię w Apache?

My apache - ustawienia -

<VirtualHost *:80> 
     ServerAdmin [email protected] 

     DocumentRoot /home/ubuntu/server/ 
     <Directory /> 
       Options None 
       AllowOverride None 
     </Directory> 

     <Directory /home/ubuntu/server/apstat> 
       AllowOverride None 
       Order allow,deny 
       allow from all 
     </Directory> 

     <Location "/apstat"> 
       SetHandler python-program 
       PythonHandler django.core.handlers.modpython 
       SetEnv DJANGO_SETTINGS_MODULE apstat.settings 
       PythonOption django.root /home/ubuntu/server/ 
       PythonDebug On 
       PythonPath "['/home/ubuntu/server/'] + sys.path" 
     </Location> 

</VirtualHost> 

Mam teraz siedział dłużej niż jeden dzień w tej sprawie. Jeśli ktoś może mi pomóc, byłoby to bardzo miłe.

+1

Znaleźliśmy problem. Wewnątrz __init__.py, robiłem kilka inicjalizacji. W serwerze dev działało, ale w Apache pewne problemy z uprawnieniami spowodowały awarię. Django zjada błędy, więc nie jest to oczywiste. – Koran

Odpowiedz

12

Czy Twój podstawowy ma __init__.py?

+2

Tak. Właściwie to był problem. Zawierało init.py, który inicjuje log itd. Wystąpił problem z uprawnieniami metinks, które spowodowały błąd. Tak więc, kiedy testowałem z serwerem dev, działało dobrze, ale w Apache nie działa. Django spożywa aktualny dziennik błędów ;-( – Koran

+0

Można je znaleźć w dzienniku błędów apache. –

0

Zazwyczaj katalog projektu jest dodawany do sys.path, a następnie nazwa aplikacji jest używana bezpośrednio w INSTALLED_APPS oraz w importach w innych aplikacjach. Wypróbuj to.

+0

Próbowałem, ale bezskutecznie. – Koran

4

Musisz się upewnić, że projekt znajduje się w Twoim PYTHONPATH. Może spróbuj wyjściu zmienną sys.path na szczycie ustawieniach pliku:

import sys 
print sys.path 

Jeśli to nie zadziała z mod_python próby zapisu do pliku:

import sys 
file('/tmp/mysyspath.txt', 'w').write(repr(sys.path)) 

Ale nawet jeśli wola praca, tutaj jest krótkie ostrzeżenie: Odradza się w społeczności django używanie mod_python. Nie jest już utrzymywany przez jego twórców i nigdy nie był najlepszym rozwiązaniem do wdrożenia twojego projektu django. Wypróbuj mod_wsgi, jeśli jest dostępna dla Ciebie na serwerze.