python创建项目
一、准备下载
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}}   :   {{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创建项目的更多相关文章
- python 创建项目
项目骨架 nose 测试框架 Windows 10 配置 创建骨架项目目录 Windows 10 的 PowerShell mkdir projects cd projects/ mkdir skel ...
- Python 创建项目、应用
1.创建项目 django-admin startproject TestPython 2.创建应用 python3 manage.py startapp books 3.目录讲解 ├── TestP ...
- cocos2d-x使用python脚本创建项目的简单方法
本文有CC原创,转载请注明地址:http://blog.csdn.net/oktears/article/details/13297003 在cocos2d-x2.1.4以上的版本中,取消了使用vs模 ...
- Python Scrapy项目创建(基础普及篇)
在使用Scrapy开发爬虫时,通常需要创建一个Scrapy项目.通过如下命令即可创建 Scrapy 项目: scrapy startproject ZhipinSpider 在上面命令中,scrapy ...
- python Django 项目创建
注:后续如不特色说明,使用python版本均为python3 创建项目 django-admin startproject projectName 启动服务 python manage.py runs ...
- Python Django框架笔记(一):安装及创建项目
#推荐一本书<Python核心编程>(适合有一定基础的),美国人Wesley Chun编写的,京东.淘宝应该都有.我是觉得写的很好,详细.简洁.满满的干货,不像有的书整本看完也没什么用. ...
- python开发学习-day15(前端部分知识、web框架、Django创建项目)
s12-20160430-day15 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
- 使用python创建cocos2d-x项目
已准备条件: 已安装vs2012,已下载cocos2d-x sdk 2.2.3包. 旧版本号使用包里面的模板创建项目,如今新的包,使用python 来创建 1.下载安装 python https ...
- PyCharm中创建项目时,在所创建的python虚拟环境下的pip失效
在这篇博文里,我简单地叙述了我在使用PyCharm创建一个flask项目时遇到的问题,以及我解决这个问题的过程.其中比较值得注意的点有:①PyCharm创建新项目时的解释器配置②Python虚拟环境的 ...
随机推荐
- HTML5必须知道的那些事
[转自] http://www.cnblogs.com/hamy/archive/2012/02/21/2362110.html 再普及一次HTML5基础,HTML5必须知道的那些事,HTML5扫盲. ...
- 基于vue-cli搭建路飞
一.项目搭建 1. 首先进入到项目要保存的文件夹,然后执行命令如下命令初始化项目 vue init webpack lufei 2. 命令执行后,除了第一个填一下项目名称,其他的一路选no,这样建立的 ...
- 小问题总结:鼠标点击到输入框(input)里的时候,输入框的提示消失,鼠标再移开,输入框提示出现
问题如标题: 鼠标点击到输入框(input)里的时候,输入框的提示消失,鼠标再移开,输入框提示出现.如图所示: 做法如下: <input type="text" name ...
- PIE SDK地图书签
地图书签,可以理解为暂时记录当前地图的范围和放大级别,在后续的操作中如果想回到地图之前的状态,就可以点击保存的书签就可以回到此状态,如图所示: 地图刚加载的时候是一幅世界地图 我们将地图的中心拖到南美 ...
- java中的线程(2):如何正确停止线程之3种常见停止方式
1.常见停止方式 自定义线程,其中含退出标志位,在run中判断它. 使用interrupt()方法中断线程 使用stop方法暴力终止(已经弃用) 2.使用标志位 class TestThread ex ...
- svn server配置与TortoiseSVN、Ankhsvn+VS使用
Svn服务器与客户端安装 1. 下载安装VisualSvn-Server服务端.(过程略)http://subversion.apache.org/packages.html 2. ...
- 8086键盘输入实验——《x86汇编语言:从实模式到保护模式》读书笔记07
1.BIOS中断 我们可以为所有中断类型自定义中断处理过程,包括内部中断.硬件中断和软中断. BIOS中断,又称BIOS功能调用,主要是为了方便地使用最基本的硬件访问功能.通常,为了区分针对同一硬件的 ...
- pat1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- IBM Rational Appscan: Part 2 ---reference
http://resources.infosecinstitute.com/appscan-part-2/ By Rohit T|August 16th, 2012 ----------------- ...
- C++程序设计基础(8)main函数
注:读<程序员面试笔记>笔记总结 1.知识点 (2)main函数的形式 //first type int main() //second type int main(int argc,ch ...