Single

Python在PyCharm中利用Django开发HelloWord

首先安装Pycharm,Python,Djingo。

关闭Pycharm拼写检查 http://www.linuxidc.com/Linux/2015-12/125936.htm

Ubuntu 10.10安装PyCharm1.5 http://www.linuxidc.com/Linux/2011-09/43669.htm

PyCharm中文乱码问题的解决 http://www.linuxidc.com/Linux/2016-01/127785.htm

Ubuntu 11.10安装Python编辑器pycharm(含注册码) http://www.linuxidc.com/Linux/2012-10/71935.htm

在CentOS 6.5上安装Python2.7 http://www.linuxidc.com/Linux/2016-10/136206.htm

CentOS 7 安装Python2.7.12 http://www.linuxidc.com/Linux/2017-03/141286.htm

Ubuntu 14.04 LTS下编译安装Open Babel和Python语言绑定 http://www.linuxidc.com/Linux/2017-01/139569.htm

Ubuntu 14.04下Django+MySQL安装部署全过程 http://www.linuxidc.com/Linux/2016-02/128714.htm

Ubuntu 16.04下安装部署 Nginx+uWSGI+Django1.9.7 http://www.linuxidc.com/Linux/2016-07/133484.htm

Ubuntu 16.04下配置Django项目 http://www.linuxidc.com/Linux/2017-01/139417.htm

在PyChram中新建一个Django项目

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

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

:http://www.linuxidc.com/Linux/2017-03/142185.htm