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

Django models 如何将python代码连接到服务器?,django-models,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 a

我的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)),
)

根据您所拥有的和收到的404未找到的信息判断,我认为您将访问
localhost:8000

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

您还需要在URL中遵循正确的语法。您目前有:

('^hello/$', hello),
您需要:

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

通过转到
settings.py
文件并设置
DEBUG=True

这只是URL路由,您还可以启用更详细的调试。我们看不到任何返回
hello world
或生成错误消息的代码。这是my views.py内容:from django.http import HttpResponse def hello(请求):return HttpResponse(“hello world”)您得到的错误是什么?我有错误“404页面未找到”!