当前位置:Gxlcms > Python > 详解python在pychram中利用djingo开发helloword

详解python在pychram中利用djingo开发helloword

时间:2021-07-01 10:21:17 帮助过:93人阅读

这篇文章详解python在pychram中利用djingo开发helloword

首先安装pycheam,python,djingo。

在pychram中新建一个djingo项目

详解python在pychram中利用djingo开发helloword

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

详解python在pychram中利用djingo开发helloword

接下来在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/

详解python在pychram中利用djingo开发helloword

以上就是详解python在pychram中利用djingo开发helloword的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行