python在pychram中利用djingo開發helloword

首先安裝pycheam,python,djingo。

在pychram中新建一個djingo項目

wKioL1jA_eDwlDzvAAEdKe9dOI8939.png-wh_50

在web2目錄下新建views.py文件,目錄如下:

wKiom1jA_j-ghw_nAAEdKe9dOI8787.png-wh_50

接下來在views.py文件中編寫helloworld代碼:

# -*- coding: utf-8 -*
from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello world! This is my first trial. [筆記]")

還需要配置urls.py文件完成映射

from django.conf.urls import patterns, include, url
from web2.views import hello
from django.contrib import admin
from django.conf.urls import *
admin.autodiscover()

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

    url(r'^admin/', include(admin.site.urls)),
    ('^hello/$', hello),
)

一定要先導入hello

from web2.views import hello

然後啓動項目,在瀏覽器打開

http://127.0.0.1:8000/hello/

wKiom1jA_wfg8rVQAAAslvNsNDw618.png-wh_50

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