Python在PyCharm中利用Django开发HelloWord

CentOS 6.5上安装Python2.7 

CentOS 7 安装Python2.7.12 

Ubuntu 14.04 LTS下编译安装Open Babel和Python语言绑定

Ubuntu 14.04下Django+MySQL安装部署全过程

Ubuntu 16.04下安装部署 Nginx+uWSGI+Django1.9.7 

Ubuntu 16.04下配置Django项目 

在PyChram中新建一个Django项目

Python在PyCharm中利用Django开发HelloWord

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

Python在PyCharm中利用Django开发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',),
    # url(r'^blog/', include('blog.urls')),
 
    url(r'^admin/', include(admin.site.urls)),
    ('^hello/$', hello),
)

一定要先导入hello
from web2.views import hello然后启动项目,在浏览器打开
:8000/hello/

Python在PyCharm中利用Django开发HelloWord

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/aa77a4c1338924422416cacb68136896.html