Найти - Пользователи
Полная версия: Статика в Django + Apache [SOLVED]
Начало » Django » Статика в Django + Apache [SOLVED]
1
fongostev
Добрый день!
Вопрос стар, как мир, но, увы, два дня мучений ничего не дали.
Не работает статика ни в админке, ни в основном проекте. Появилось после обновления django.
Debian
Django 1.4.1
Pyhon 2.6

urls.py
from django.contrib import admin
from django.conf.urls.defaults import *
from transctrl_web import views
from transctrl_web import transctrl_web_backend as backend
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
admin.autodiscover()
urlpatterns = patterns('',
    url(r'^index/', views.print_objects),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', 'django.contrib.auth.views.login', {'template_name': 'registration/login.html'}),
    url(r'^logout/', backend.logout),
    url(r'^getstatus/', views.web_cmd, {'cmd': backend.cmd_get_status}),
    url(r'^control/', views.web_cmd, {'cmd': backend.cmd_control_channels}),
    url(r'^restart/all/', views.web_cmd, {'cmd': backend.cmd_restart_all}),
    url(r'^release/name/$', views.web_operation, {'cmd': backend.cmd_release_name, 'type': 'name'}),
    url(r'^release/ip/$', views.web_operation, {'cmd': backend.cmd_release_ip, 'type': 'ip'}),
    url(r'^release/pattern/$', views.web_operation, {'cmd': backend.cmd_release_pattern, 'type': 'pattern'}),
    url(r'^stop/all/', views.web_cmd, {'cmd': backend.cmd_stop_all}),
#    url(r'^change/slot/$', views.web_change, {'type': 'slot'}),
#    url(r'^change/channel/$', views.web_change, {'type': 'channel'}),
    url(r'^add/slot/$', views.web_add, {'type': 'slot'}),
    url(r'^add/channel/$', views.web_add, {'type': 'channel'}),
    url(r'^import/', views.web_import, {'Error': "You want to reimport tables", 'cmd': "Some problems"}),
)
urlpatterns += staticfiles_urlpatterns()

server.ru
<VirtualHost *:80>
    # Описание сервера
    ServerAdmin 
    ServerName
    # Логи
    ErrorLog    /home/transctrl/logs/error_log
    CustomLog   /home/transctrl/logs/access_log common
    LogLevel warn
    # wsgi-обработчик (см. ниже)
    WSGIScriptAlias / /home/transctrl/deploy/django.wsgi
    # Параметры запуска wsgi
    WSGIDaemonProcess tr-site user=webuser group=web \
                      processes=1 threads=4 maximum-requests=100 display-name=apache-web-wsgi
    WSGIProcessGroup tr-site
    <Directory '/home/data/'>
        AllowOverride All
        Allow From All
    </Directory>
    Alias "/static/admin/" "/home/transctrl/static/admin/"
    <Location "/static/admin/">
        SetHandler None
    </Location>
    Alias "/static/" "/home/transctrl/static/"
    <Location "/static/">
        SetHandler None
    </Location>
</VirtualHost>

Template's part
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <script src="{{ STATIC_URL }}jQuery.js"></script>
        <script src="{{ STATIC_URL }}noty/jquery.noty.js"></script>
        <script src="{{ STATIC_URL }}noty/layouts/top.js"></script>
        <script src="{{ STATIC_URL }}noty/themes/default.js"></script>
        <script src="{{ STATIC_URL }}domtab/domtab.js"></script>
        <link rel="stylesheet" href="{{ STATIC_URL }}domtab/domtab.css" media="all" />

settings.py
PROJECT_ROOT = os.path.normpath( os.path.dirname( __file__) )
STATIC_ROOT = os.path.join( PROJECT_ROOT, 'static' )
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static'
Antonio051
fongostev
Добрый день!
settings.py
PROJECT_ROOT = os.path.normpath( os.path.dirname( __file__) )
STATIC_ROOT = os.path.join( PROJECT_ROOT, 'static' )
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static'

Может так:
STATIC_URL = ‘/static/’
В вашем случаем получается, что статика отдаётся как:
<script src="/staticdomtab/domtab.js"></script>

Гляньте логи. Там должны ошибки 404 на ваши файлы.
fongostev
Antonio051, спасибо, Вы дали мне правильное направление. Ошибка 403 решилась chmod 777 на static/.
Даже странно, как все просто получилось.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB