如何将python代码连接到服务器?

时间:2013-05-09 14:06:56

标签: django-models

我在views.py中有一个打印字符串的函数。我已经通过django运行本地服务器。 我写了这段代码。这个项目的页面必须显示“hello world”这个词,但它没有! 你能帮我解决一下吗?

from django.conf.urls.defaults import *
from mysite.views import hello

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

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

# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)

1 个答案:

答案 0 :(得分:0)

根据你所拥有的东西来判断并且没有找到404,我认为你只是去localhost:8000

但是,您的网址设置说您应该转到localhost:8000/hello/(您没有为索引模式设置页面url(r'^$', hello)

您还需要在网址中使用正确的语法。你现在有:

('^hello/$', hello),

你需要:

url(r'^hello/$', hello),

您还可以转到settings.py文件并设置DEBUG = True

来启用更详细的调试