一、准备下载

python3.6.6 https://www.python.org/downloads/windows/(需要注意你的电脑是32位还是64位)

mysql 5.1.72 https://dev.mysql.com/downloads/mysql/

pip 18.0 https://pypi.org/project/pip/

Django 1.11.7  https://www.djangoproject.com/download/ 或者用pip install django=18.0(注意如果是2.0的话,会出错的)

pymysql  0.9.0  pip3 install PyMySQL

软件pycharm http://www.jetbrains.com/pycharm/

二、创建项目

1.开始创建项目

文件----新项目---django

点击执行,然后在浏览器中输入127.0.0.1:8000可以看到html页面

项目:pythonweb_demo app名称:pythonweb

2.项目中文件代码

python_demo/python_demo/seeting.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pythonweb' //添加你的app的名字
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',//采用mysql
'NAME': 'appdata',//你的
'USER': 'root',//登录库用户名
'PASSWORD': '123456',//密码
'HOST': '',//主机
'PORT': '3306',//端口 注意用这个端口号,注意拼写 其他的应该没问题
'OPTIONS': {'isolation_level': None}//链接数据库需要填写这个
},
} 
STATIC_URL = '/static/'
STATICFILES_DIRS = [
(
os.path.join(BASE_DIR, "static")
)
]

python_demo/python_demo/urls.py

from django.contrib import admin
from pythonweb import views
from django.conf.urls import url urlpatterns = [
url('admin/', admin.site.urls),
url('views/', views.index)
]

python_demo/pythonweb/models.py

from django.db import models
# -*- coding: utf-8 -*-
# Create your models here.
class Mobile(models.Model):
brand = models.IntegerField()
size = models.FloatField()
price = models.IntegerField()
# age = models.IntegerField()
print(brand)
def __unicode__(self):
# 在Python3中使用 def __str__(self)
return self

python_demo/pythonweb/views.py

from django.shortcuts import render
from pythonweb.models import Mobile # Create your views here.
def index(request):
print(1)
str = Mobile.objects.all()
return render(request, 'index.html', {'str': str})

python_demo/templates/index.html

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>后台主页面</title>
</head>
<body>
<div class="home">
姓名为name1的年龄为:{{ str.price }}
{% for str in str %}
<p>{{str.brand}}&nbsp&nbsp&nbsp:&nbsp&nbsp&nbsp{{str.price}}</p>
<br>
{% endfor %}
<h3>这是home页面</h3>
</div>
<script src="/static/jqueryHome.js"></script>
</body>
</html>

三、开始创建数据库

1.开始链接数据库,在cmd中打开python,执行命令

python manage.py makemigrations pythonweb

python manage.py migrate pythonweb

这样就可以在数据库中创modle.py中对应表

2.在cmd中打开mysql,查看表是否创建成功

mysql>show databases;//查看数据库

mysql>use appdata;//进入数据库

mysql>show tables;//崭新当前数据库中表

mysql>desc mobile;//展示表中的参数

mysql> SELECT * FROM appdata.pythonweb_mobile m;//展示表中数据 mobile是表 python_web是你的app的名字 自动添加的

mysql> insert into pythonweb_mobile(brand,size,price) values;//添加数据

mysql>SELECT * FROM appdata.pythonweb_mobile m;//展示数据是否添加成功

3.在pyCharm执行

4.在浏览器中打开127.0.0.1

四、资料

1.https://blog.csdn.net/gitzliu/article/details/54627517

https://www.2cto.com/database/201806/752142.html

https://blog.csdn.net/pugongying1988/article/details/72870264 field

五、错误:

1.Your STATICFILES_DIRS setting is not a tuple or list; "

ImproperlyConfigured: Your STATICFILES_DIRS setting is not a tuple or list; perhaps you forgot a trailing comma?

解决方案:

找到settings.py文件,

把STATICFILES_DIRS=(os.path.join(BASE_DIR,'static'))

改为STATICFILES_DIRS=[(os.path.join(BASE_DIR,'static'))]

2.安装mysqlclient出现错误: install --record C:\Users\admin\AppData\Local\Temp\pip-record-2fiij4o6\install-record.txt --single-version-externally-managed --compile" failed with error

python==3.6

3.django连接mysql

https://blog.csdn.net/liuweiyuxiang/article/details/71101910

4.错误django.db.utils.ProgrammingError: (1064"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED' at line 1")

解决:setting.py--->DATABASES 添加  'OPTIONS':{'isolation_level':None}

5.运行错误TypeError: context must be a dict rather than set.

https://blog.csdn.net/zoulonglong/article/details/79611562

												

python创建项目的更多相关文章

  1. python 创建项目

    项目骨架 nose 测试框架 Windows 10 配置 创建骨架项目目录 Windows 10 的 PowerShell mkdir projects cd projects/ mkdir skel ...

  2. Python 创建项目、应用

    1.创建项目 django-admin startproject TestPython 2.创建应用 python3 manage.py startapp books 3.目录讲解 ├── TestP ...

  3. cocos2d-x使用python脚本创建项目的简单方法

    本文有CC原创,转载请注明地址:http://blog.csdn.net/oktears/article/details/13297003 在cocos2d-x2.1.4以上的版本中,取消了使用vs模 ...

  4. Python Scrapy项目创建(基础普及篇)

    在使用Scrapy开发爬虫时,通常需要创建一个Scrapy项目.通过如下命令即可创建 Scrapy 项目: scrapy startproject ZhipinSpider 在上面命令中,scrapy ...

  5. python Django 项目创建

    注:后续如不特色说明,使用python版本均为python3 创建项目 django-admin startproject projectName 启动服务 python manage.py runs ...

  6. Python Django框架笔记(一):安装及创建项目

     #推荐一本书<Python核心编程>(适合有一定基础的),美国人Wesley Chun编写的,京东.淘宝应该都有.我是觉得写的很好,详细.简洁.满满的干货,不像有的书整本看完也没什么用. ...

  7. python开发学习-day15(前端部分知识、web框架、Django创建项目)

    s12-20160430-day15 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  8. 使用python创建cocos2d-x项目

    已准备条件: 已安装vs2012,已下载cocos2d-x sdk 2.2.3包. 旧版本号使用包里面的模板创建项目,如今新的包,使用python  来创建 1.下载安装  python  https ...

  9. PyCharm中创建项目时,在所创建的python虚拟环境下的pip失效

    在这篇博文里,我简单地叙述了我在使用PyCharm创建一个flask项目时遇到的问题,以及我解决这个问题的过程.其中比较值得注意的点有:①PyCharm创建新项目时的解释器配置②Python虚拟环境的 ...

随机推荐

  1. [转] Java 使用Try-with-resources自动关闭资源

    [From] https://blog.csdn.net/wtopps/article/details/71108342 Try-with-resources Try-with-resources是J ...

  2. spark第二篇:Application Submission Guide

    提交应用 Spark的bin目录中的spark-submit脚本用于启动集群上的应用程序.它可以通过一个统一的接口使用所有Spark支持的集群管理器. 绑定应用程序的依赖 如果你的代码依赖其他项目,你 ...

  3. (转)[Shell]tr命令详解

    原文:http://blog.csdn.net/sunnyyoona/article/details/52986893 1. 用途 tr,translate的简写,主要用于压缩重复字符,删除文件中的控 ...

  4. TOJ 1258 Very Simple Counting

    Description Let f(n) be the number of factors of integer n. Your task is to count the number of i(1 ...

  5. GridView, ListView 区别

    ListView, GridView部分的类层次结构 AbsListView的xml属性 android:listSelector 当前item高亮时,显示的drawable android:draw ...

  6. Java入门系列-08-选择结构

    这篇文章为你搞懂2个问题 if-else选择结构的使用? switch 的使用? 前面我们学习的代码都是直上直下的执行,还不会"拐弯",这篇文章带大家来看一下会"拐弯&q ...

  7. 使用request与正则表达式爬取bangumi动画排行榜

    import json import requests from requests.exceptions import RequestException import re import time d ...

  8. fullpage的使用以及less, Sass的属性和JQuery自定义插件的声明和使用

    使用fullpage的步骤   1 导入JQuery.js fullpage,js fullpage.css 2 组建网页布局,最外层id="fullpage" 单页class=& ...

  9. springboot和mybatis集成,自动生成model、mapper,增加mybatis分页功能

    整体思路和http://www.cnblogs.com/mahuan2/p/5859921.html相同. 主要讲maven的pom.xml和一些配置变化,详细说明. 软件简介 Spring是一个流行 ...

  10. java使用poi.3.10读取excel 2007以上版本(xlsx格式)

    1.在使用过程中,一直报错 throw new ClassNotFoundException(name);原因:没有导入xmlbeans-2.6.0.jar包,建议在使用poi时,将所有包都导入进工程 ...