加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

资深程序员教你用python创建一个简单的Django新手教程!看完必会

发布时间:2020-12-17 01:20:30 所属栏目:Python 来源:网络整理
导读:p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,Arial,'Hiragino Sans GB','Microsoft YaHei',simsun;vertical-align:baseline;color:rgb(93,93,93);background-color:rgb(255,255,255);"

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,Arial,'Hiragino Sans GB','Microsoft YaHei',simsun;vertical-align:baseline;color:rgb(93,93,93);background-color:rgb(255,255,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">我这里直接选择的是python最新版本3.6.5进行开发

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">下载完成后,点击安装,安装完成后你需要设置Python环境变量,一般在安装的过程中选择Add to Path这个选项,程序会自动的设置Python环境变量,不需要自己手动去添加环境变量,省去了一些时间。

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">安装完Python开发环境以后 我们cmd打开命令行 输入“python”(如下)

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">出现如上图所示的提示后,表示我们的Python开发环境已经安装成功了,如果命令行中显示的是python不是内部或外部命令,也不是可运行的程序,那么请手动把python添加到环境变量中去

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">接下来已win7系统为例

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">计算机--右键--属性 选择高级系统属性

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">选择环境变量,在选择path,将python的安装路径添加到后面,记得用;分隔开来

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">安装完python以后,接下来就是安装我们开发所需要的Django框架,我们通过pip来安装Django框架,因为我们安装的是最新版本的python,直接打开命令行输入pip,会出现如下的结果

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">设置完后点击创建,创建完成后的目录如下

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">我新建了一个?<span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:700;line-height:inherit;font-family:inherit;vertical-align:baseline;">dj?目录,其中还有一个?<span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:700;line-height:inherit;font-family:inherit;vertical-align:baseline;">dj?目录,这个子目录中是一些项目的设置<span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:700;line-height:inherit;font-family:inherit;vertical-align:baseline;">settings.py文件,总的urls配置文件?<span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:700;line-height:inherit;font-family:inherit;vertical-align:baseline;">urls.py?以及部署服务器时用到的?<span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:700;line-height:inherit;font-family:inherit;vertical-align:baseline;">wsgi.py?文件,<span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:700;line-height:inherit;font-family:inherit;vertical-align:baseline;">init.py?是python包的目录结构必须的,与调用有关。

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">我们再来新建一个应用(app)名叫cmdb

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">在命令行后面我们输入 python manage.py startapp cmdb, 这里需要注意的是把diango的安装路径也要添加到系统的环境变量里面去,不然到时候会报错

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<pre style="margin-bottom:0px;padding-right:0px;padding-left:0px;border:0px;font-size:18px;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(93,255);"><pre class="source-code" style="margin-bottom:0px;padding:15px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;background:rgb(243,244,245);"><code style="margin:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;">在这里我们可以设置访问端口<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<pre style="margin-bottom:0px;padding-right:0px;padding-left:0px;border:0px;font-size:18px;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(93,245);"><code style="margin:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;">设置完以后点击运行,可以看到我们的项目已经在本地跑起来了<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<pre style="margin-bottom:0px;padding-right:0px;padding-left:0px;border:0px;font-size:18px;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(93,245);"><code style="margin:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;">接下来我们打开浏览器,输入端口号,输入访问路径,可以看到在浏览器我们可以访问到该页面<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<pre style="margin-bottom:0px;padding-right:0px;padding-left:0px;border:0px;font-size:18px;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(93,245);"><code style="margin:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;">就这样一个由django框架搭建的一个最简单的项目就这样完成了,怎么样,是不是感觉 <span style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(149,65,33);">so easy!!
后续还会写一些关于django的简单教程。。。。。。。。<p style="margin-top:1em;margin-bottom:0px;border:0px;font-size:18px;line-height:inherit;font-family:helvetica,255);">

<h1 style="margin-top:40px;margin-bottom:26px;padding:0px;border:0px;font-size:34px;line-height:34px;font-family:Arial;vertical-align:baseline;color:rgb(89,89,89);background-color:rgb(255,255);">资深程序员教你用python创建一个简单的Django新手教程!看完必会

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读