0

我开始使用 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/hellohttp://example 的形式。 com:8000/详细信息。我需要 .htaccess 来实现吗?

4

1 回答 1

0

在我研究丹尼尔建议我看的内容时,我已经解决了这个问题。

from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView

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

urlpatterns = patterns('',
    # Examples:
    (r'^detail/', TemplateView.as_view(template_name="detail.html")),
    # 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)),
)
于 2013-04-10T16:57:09.810 回答