我試圖部署在一個子我Django應用程序管理靜態文件,說example.djangoapp.com,一切工作正常,除了我的Django管理站點,當我是去點擊鏈接管理網站,它路由到不同的網址。當我使用管理員網址模板標記時,會發生這種情況,即它將路由到djangoapp.com/index而不是example.djangoapp.index.fcgi/login(這是管理站點)。Django的不是服務使用FastCGI
刪除管理URL模板標籤後,我把一個絕對URL的重定向到管理界面,這做工精細和管理的網站顯示,但它的靜態文件沒有提供。所以我在兩者之間。
我在服務器上部署一個在共享主機
我的問題上運行的FastCGI:
1)選項1(使用管理URL模板標籤):
我如何獲得的Django重定向我到正確的管理網站(www.example.djangoapp.index.fcgi/login),而不是將我重定向到(www.djangoapp.com/index)。
2)當使用絕對URL: 現在我硬編碼我的家庭模板索引頁面的管理鏈接,這工作正常,但django管理靜態文件不送達。他們如何得到服務?
原諒他我的無知,但我一直在這個掙扎了幾個星期。我決定硬編碼的網址,但管理網站靜態文件仍然沒有服務。
下面是我的settings.py,urls.py和index.html(其中i硬編碼的管理站點URL)。此代碼與上面的具有硬編碼管理網站網址的選項2內嵌。
settings.py
WSGI_APPLICATION = 'cconnect_web.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
'CONN_MAX_AGE': 3600,
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Africa/Cairo'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/cconnect/static/'
STATIC_ROOT = '/home4/techaven/public_html/cconnect/static'
FORCE_SCRIPT_NAME="/index.fcgi/"
Urls.py
from django.conf.urls import *
from django.conf.urls import include, url
from django.contrib import admin
from cconnect_frontEnd import views
from . import settings
#app_name = 'cconnect_frontEnd
urlpatterns = [
url(r'^$', views.index, name ='index'),
url(r'^backend/', include('Back_End.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root':settings.STATIC_ROOT}),
]
urlpatterns += patterns('Back_End.views',
(r'^login/$', 'login_view'),
)
admin.site.site_header = 'Cconnect Administration.'
的index.html
<body>
<div class="header-wrapper">
<nav>
<div class=nav-wrapper">
{% load staticfiles %}
<img src="{% static "cconnect_frontEnd/images/slide/logo.png" %}" alt="Conference Connect"/>
<ul class="right hide-on-med-and-down">
{% load admin_urls %}
<li><a href="http://cconnect.techavenue137.rw/index.fcgi/admin">Sign In</a></li>
<li><a href="#feature-title">Features</a></li>
<li><a href="#demo-video">Videos</a></li>
</ul>
index.fcgi
import os
import sys
from flup.server.fcgi import WSGIServer
from django.core.wsgi import get_wsgi_application
sys.path.insert(0, "/home4/techaven/public_html/cconnect/cconnect_web/")
os.chdir("/home4/techaven/public_html/cconnect/cconnect_web")
os.environ['DJANGO_SETTINGS_MODULE'] = "cconnect_web.settings"
WSGIServer(get_wsgi_application()).run()
的.htaccess
AddHandler fcgid-script .fcgi
DirectoryIndex index.fcgi
RewriteEngine On
RewriteCond %{HTTP_HOST} ^cconnect\.techavenue137\.rw$ [OR]
RewriteCond %{HTTP_HOST} ^www\.cconnect\.techavenue137\.rw$
RewriteRule ^/?$ "http\:\/\/www\.techavenue137\.rw\/cconnect\/index\.fcgi" [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cconnect/
RewriteRule ^index\.fcgi$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^/static/
RewriteRule ^(.*)$ /cconnect/index.fcgi/$1 [L]
</IfModule>
感謝您的幫助,再次請原諒我的愚蠢的問題。
你的問題並不愚蠢。首先,我假設你已經收集了靜態文件('python manage.py collectstatic')其次,你的web服務器是否被配置爲提供文件? (例如,Nginx應該有一個'location/cconect/static /','alias'是你的靜態根目錄]。當你使用dev服務器進行嘗試時會發生什麼? ('python manage.py runserver')如果沒有顯示,請檢查錯誤消息。 –
謝謝keenan,是的,我的服務器配置爲服務於靜態文件,在開發服務器上一切正常,管理網站服務。在生產服務器上的其他靜態文件只服務於管理站點靜態文件不提供。我的想法是,錯誤是在網址路由。我不知道該怎麼去做。 – Arnold
啊,好吧。是的,這個問題是與網址路由。檢查缺失的元素時,錯誤代碼是什麼?是404,403,500嗎?另外,你可以發佈你的web服務器配置的應用程序? –