2012-03-24 75 views
1

我下面一個tutorial for django,即時通訊主辦我的免費託管的測試項目,的Django的hello world不顯示

託管工作正常使用Python,例如Django的外殼,

,但我看不到正確的數據在我的index.html或有存取權限的/管理員

,所以我認爲這是一個錯誤的路徑問題?

所以請對這個菜鳥問題諮詢,

這是我有我的文件的文件夾/home/mako34/www/blog

這裏我的代碼:

我想設置爲數據庫正確配置,因爲它是建立在sqlite的數據庫,以及必要的文件夾

settings.py中

import os 
* 
* configure connection do db, etc 
* 

ROOT_URLCONF = 'blog.urls' 

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 
    # Always use forward slashes, even on Windows. 
    # Don't forget to use absolute paths, not relative paths. 
    os.path.join(os.path.dirname(__file__),'templates'), # creates a absolute path 
) 

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'blog', 
    # Uncomment the next line to enable the admin: 
    'django.contrib.admin', 
    # Uncomment the next line to enable admin documentation: 
    # 'django.contrib.admindocs', 
) 

urls.py

from django.conf.urls.defaults import patterns, include, url 

# Uncomment the next two lines to enable the admin: 
from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
    # Examples: 
    # url(r'^$', 'blog.views.home', name='home'), 
    # url(r'^blog/', include('blog.foo.urls')), 

    # Uncomment the admin/doc line below to enable admin documentation: 
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), 
    (r'^, 'blog.views.index'), #<------------------- index/root entry 
    # Uncomment the next line to enable the admin: 
    url(r'^admin/', include(admin.site.urls)), 


) 

的index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <title>My Blog</title> 
    </head> 

<body> 
    <H1>Test Django</H1> 
    <div id="content"> 
    {% block content %} 
    {% endblock %} 
    </div> 
</body> 

</html> 

所以我錯過了什麼IM?

,所以我可以看到我的數據索引HTML [因爲現在它顯示在他們

標籤{% block content %} {% endblock %}並且沒有數據,不能有存取權限http://mako34.alwaysdata.net/blog/admin/

的感謝!

+1

您是否配置了WSGI兼容的Web服務器以在您的項目中使用wsgi.py模塊? – kosii 2012-03-24 08:49:30

+0

@kosii,嘿,不,我沒有,將搜索如何做到這一點?,謝謝! – MaKo 2012-03-24 08:54:56

+0

https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/ – kosii 2012-03-24 08:55:50

回答

1

您的網址應該是這樣的:

urlpatterns = patterns('', 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^', 'blog.views.index'), 
) 

請注意,你想工作的索引網址現在被包裹在一個url()通話。另外,索引網址現在位於管理網址後面,以便引用/admin的網址由管理網址處理,而不是您已定義的所有index網址。

URL處理程序在第一個匹配上工作。你的url(r'^')匹配一切,所以不給機會管理網址的工作。您應該將其更改爲url(r'^$'),該網址將匹配「無路徑」網址,而不是「每個網址」。請注意添加$符號,標記模式的結束。

編輯:

好的,現在我明白你的問題了。你要做的是在一個特定的服務器路徑上部署一個django應用程序,該路徑需要在URL路徑中有一個前綴。

這就是通常是一個標準的URL:

http://www.example.com/ 
http://www.example.com/admin/ 
http://www.example.com/index/ 

相反,這是你想要做什麼:

http://www.example.com/myapp/ 
http://www.example.com/myapp/admin/ 
http://www.example.com/myapp/index/ 

Django的通常預期在根本上部署您的應用程序網址,沒有路徑。該路徑用於查找哪個內部django應用程序應該處理該請求。

有兩種方法可以解決您的問題。第一個,我認爲正確的方法是使用here描述的網站框架。

其他的,就是前綴添加到所有的網址在URL模式,像這樣:

urlpatterns = patterns('', 
    url(r'^blog/admin/', include(admin.site.urls)), 
    url(r'^blog/$', 'blog.views.index'), 
) 

但你還需要記住你的「博客​​」前綴添加到期望像URL幾個設置LOGIN_REDIRECT等等

你真的應該做的是讓django工作在URL:mako34.alwaysdata.net並忘記/ blog /完全,但修改apache以將所有請求重定向到mod_wsgi。

+0

嗨,謝謝,做了建議更改,但仍然沒有正確顯示index.html(http://mako34.alwaysdata.net/blog/),並在/ admin(http://mako34.alwaysdata.net/blog/admin/)上顯示Not found ,,請求的URL /博客/ admin /在此服務器上找不到。 – MaKo 2012-03-24 09:57:56

+0

@MaKo你應該爲管理員打的網址是mako34.alwaysdata.net/admin。您的博客的網址應該是mako34.alwaysdata.net。謝謝你的回覆,請給出一個破解 – 2012-03-24 10:04:33

+0

,那麼url模式如何? url(r'^ admin /',include(mako34.alwaysdata.net/admin)), url(r'^','mako34.alwaysdata.net'),;;;因爲我試過這個,但仍然不工作,或者它應該不同?謝謝! – MaKo 2012-03-24 10:08:08