2013-01-18 14 views
1

我有一個Django 1.4項目,運行在Python 2.7中,我正在使用Dajaxice 0.5.4.1。我已經在我的開發機器上安裝了它(Windows 7),並且一切正常。但是,當我將我的應用程序部署到生產服務器(Ubuntu 12.04)時,我收到dajaxice.core.js文件的404錯誤,無論如何都無法解決此問題。生產服務器與所有軟件的版本完全相同。Dajaxice在生產服務器上找不到

我的項目結構如下:

/myproject 
/myproject/myproject-static/ <-- all the static files are here 
/myproject/myproject-static/css/ 
/myproject/myproject-static/img/ 
/myproject/myproject-static/js/ 
/myproject/templates/ 

/myproject/myproject/ 
/myproject/main/ 
/myproject/app1/ 
/myproject/app2/ 
/myproject/app3/ 
etc. 

我是繼Dajaxice安裝步驟here,把一切在它的地方(在settings.py,urls.py中and base.html`文件)。

settings.py文件也具有這些值:

from unipath import Path 
PROJECT_ROOT = Path(__file__).ancestor(3) 

STATIC_ROOT = '' 
STATIC_URL = '/myproject-static/' 
STATICFILES_DIRS = (
    PROJECT_ROOT.child('myproject-static'), 
) 
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder', 
    'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
    'dajaxice.finders.DajaxiceFinder', 
) 

DAJAXICE_MEDIA_PREFIX = "dajaxice" 
DAJAXICE_DEBUG = True 

我在django.conf文件的Alias指令,它看起來是這樣的:

Alias /myproject-static/ "/path/to/myproject/myproject-static/" 

我我的生產服務器上做collectstatic並得到了所有靜態文件收集在我的項目的根目錄中的幾個文件夾中。所以,現在當我查看我部署的網站時,我可以看到CSS已正確應用,JavaScript工作正常,並且網站周圍的導航按預期工作。一切都很好,除非Ajax完全破壞,因爲從未包含dajaxice.core.js

/myproject 
/myproject/myproject-static/ <-- all the static files are originally here 
/myproject/myproject-static/css/ 
/myproject/myproject-static/img/ 
/myproject/myproject-static/js/ 
/myproject/templates/ 

/myproject/admin/ <-- folder created with 'collectstatic' command 
/myproject/css/ <-- folder created with 'collectstatic' command 
/myproject/dajaxice/ <-- dajaxice.core.js is located here 
/myproject/django_extensions/ <-- folder created with 'collectstatic' command 
/myproject/img/ <-- folder created with 'collectstatic' command 
/myproject/js/ <-- folder created with 'collectstatic' command 

/myproject/myproject/ 
/myproject/main/ 
/myproject/app1/ 
/myproject/app2/ 
/myproject/app3/ 
etc. 

我做得完全錯了自己在這裏的靜態文件:採集靜態這個樣子的後

我的項目文件夾結構?
還有什麼我應該嘗試解決這個簡單的錯誤?

+0

嗨,我有一個類似的問題,你最終解決你的問題嗎? – lamba

回答

1

您是否檢查了其餘資產dajaxice.core.js是否在您的static/dajaxice文件夾中?如果沒有,問題可能與STATICFILES_FINDERS的思念配置有關,檢查Installing dajaxice again

另一個常用問題與collectstatic和dajaxice是使用此選項,您運行使用--link第一?

希望這有助於

+0

嗨豪爾赫,謝謝你的回答!我改變了我的文件夾結構,並相應地編輯了我原來的帖子。當我收集靜態文件時,我沒有使用「--link」選項。此外,'dajaxice.core.js'在位於我的項目根目錄下的dajaxice文件夾中。我試圖在我原來的帖子中稍微解釋一下。 – errata

+0

我可能忘了提及我沒有檢查提供的用於安裝dajaxice的鏈接,並且我非常確定所有東西都在它的位置上。正如我已經提到的,一切工作在開發服務器(Windows 7)上,但是當我將它部署在生產服務器上時,它會失敗...... – errata

1

我花了幾個小時,這個問題拼殺。這很瘋狂,因爲儘管所有的dajax和dajaxice設置都在一個通用的基本設置文件中,但是在我的開發環境中一切都很好,但在測試服務器上卻沒有。我從來沒有使用標準路線工作。但這是一個非常簡單的修復方法:

1)將dajaxice.core.js下載到任何靜態目錄中。您可以找到您的dajaxice目錄中的JS在你的項目根:

項目/ dajaxice/dajaxice.core.js

在我的情況,我把文件以及所有我的其他的JS庫靜態/ JS 。與正常的日常鏈接到JS庫

{% dajaxice_js_import %} 

2)在您的網頁,更換此。在我的情況下:

<script src="/static/js/dajaxice.core.js" type="text/javascript"></script> 

不幸的是,這個補丁只適用於開發的代碼。如果您在開發環境中使用它,則新的dajaxice代碼將被註冊到原始項目/ dajaxice /位置,因此在開發任何新代碼後必須將該文件複製到靜態。

相關問題