django學習2-第一個Django頁面:Hello World

  1. 在url.py中寫入URL

  • 一定要導入視圖:

from.mysite import hello
url(r'^hello/$',hello), #r表示不轉義特殊字符。

2.定義一個views.py 寫入下面的語句

from django.http import HttpResponse

def hello(request):
   return HttpResponse("Hello world")

3.這樣輸入python manage.py runserver 訪問127.0.0.1:8000/hello/ 就會看到helloworld了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章