我开始使用 django,这就是我的看法
from django.template import Context, loader
from datetime import datetime
from django.http import HttpResponse
def hello_view(request):
""" Simple Hello World View """
t = loader.get_template('helloworld.html')
c = Context({
'current_time': datetime.now(),
})
return HttpResponse(t.render(c))
def detail_view(request):
return HttpResponse("You're looking at detail view")
我的 urls.py 文件看起来像这样
from django.conf.urls import patterns, include, url
from posted.views import hello_view
#from posted.views import detail_view
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', view=hello_view, name='hello_page'),
#url(r'^$', view=detail_view, name='detail_page'),
# url(r'^posts/', include('posts.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)),
)
当我运行服务器并访问http://example.com:8000/时,会显示 hello_view。我希望我的网址采用http://example.com:8000/hello或http://example 的形式。 com:8000/详细信息。我需要 .htaccess 来实现吗?