【发布时间】:2012-04-08 15:58:59
【问题描述】:
我正在关注tutorial for django,我将我的项目托管在免费托管中进行测试,
主机在 python 和 django shell 上运行良好,
但我在 index.html 中看不到正确的数据或无法访问 /admin
所以我认为是路径错误的问题?,
所以请就这个菜鸟问题提出建议,
这是我保存文件的文件夹/home/mako34/www/blog
这是我的代码:
我想在创建 sqlite db 和必要的文件夹时为 db 正确配置了设置
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>
那我错过了什么?
所以我可以看到我的索引 html 和数据 [因为现在它显示标签 {% block content %}
{% endblock %} 并且其中没有数据
并且无法访问http://mako34.alwaysdata.net/blog/admin/
谢谢!
【问题讨论】:
-
您是否配置了兼容 WSGI 的网络服务器以在您的项目中使用 wsgi.py 模块?
-
@kosii ,嘿,不,我没有,会搜索如何做到这一点?,谢谢!
-
这可能只是一个错字:您缺少正则表达式的结束引号:
(r'^, 'blog.views.index'),应该是(r'^', 'blog.views.index'), -
@bernie tnx 我修正了这个错字,但仍然没有显示索引,干杯