一、准备下载

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. P1077

    f[i][j]:i种花放j盆的方案数 #include<bits/stdc++.h> using namespace std; const int maxn = 3e2+11; const ...

  2. java8 方法引用与lambda

    List<String> list = new ArrayList<>(); //list.stream().filter((String s)->System.out. ...

  3. PHPCMS中load_model,load_app_class, load_sys_func

    phpcms v9 二次开发: 在一个项目开发中遇到需要二次开发,但我们需要了解load_model,load_app_class, load_sys_func的含义: 1.调用数据库模型 //从”p ...

  4. Oracle9i之xmltype应用(1)

    oracle从9i开始支持一种新的数据类型-- xmltype,用于存储和管理xml数据,并提供了很多的functions,用来直接读取xml文档和管理节点.下面将介绍xmltype的一些基本使用. ...

  5. Merge Sorted Array II

    Merge two given sorted integer array A and B into a new sorted integer array. Example A=[1,2,3,4] B= ...

  6. 写给初学者的话---linux使用说明

    2018年noip上海赛区可以使用window操作系统的美梦终究还是破灭了!!!!上海大部分noip选手都陆陆续续开始改linux........好吧,那我们今天来看看linux操作系统中,noip选 ...

  7. oracle执行update语句卡住不动

    一.问题探究 开发的时候debug到一条update的sql语句时程序就不动了,然后我就在plsql上试了一下,发现plsql一直在显示正在执行,等了好久也不出结果.但是奇怪的是执行其他的select ...

  8. Ubuntu 12.04 搭建 SAMBA-SWAT(Samba Web 管理工具)

    参考了:http://linux.chinaunix.net/techdoc/net/2007/03/14/952274.shtml,对其进行了部分修改完善. 依次执行 1.sudo apt-get ...

  9. 案例45-crm练习改写客户列表使用struts2&OGNL

    1 修改CustomerAction代码 2 修改jsp/customer/list.jsp代码 <%@ page language="java" contentType=& ...

  10. Unity3D之OnGUI知识总结

    相对位置参考   http://blog.csdn.net/sunny__chen/article/details/51323265 自适应屏幕收缩  http://www.360doc.com/co ...