一 必要环境安装

  • 1首先确保安装了Python3,在此使用的系统为Ubuntu
@ubuntu:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
  • 2安装pip

    pip 是 Python 包管理工具,该工具提供了对Python 包的查找、下载、安装、卸载的功能。

    使用 sudo apt install python3-pip命令安装pip

    安装完使用此命令验证pip3是否已正确安装
fcj@ubuntu:~$ pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
  • 3 使用pip安装一个Django包



    看有些网友说是因为网络的问题,要使用国内的镜像源来加速

    如果不加速,多试几次,也能安装:



    或者使用镜像加速:比如豆瓣源

    ~$ pip3 install Django -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

二 创建Django项目

  • 1安装完成后,可以进入到Python交互模式中,查看一下所安装的Django版本
fcj@ubuntu:~$ python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
2.2.1
>>>
  • 2使用django-admin startproject xxx创建项目:
ubuntu:~/Desktop/code/PythonDemo$ django-admin startproject MyProject

Command 'django-admin' not found, but can be installed with:

sudo apt install python-django-common

根据提示使用:

sudo apt install python-django-common安装

如果还报错:

Cannot find installed version of python-django or python3-django

使用安装:

sudo apt-get install python3-django

然后即可正常创建项目!

fcj@ubuntu:~/Desktop/code/PythonDemo$ django-admin startproject MyProject
fcj@ubuntu:~/Desktop/code/PythonDemo$
  • 3查看创建的项目文件
fcj@ubuntu:~/Desktop/code/PythonDemo$ tree
.
└── MyProject
├── manage.py
└── MyProject
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py 2 directories, 5 files

  • 4运行项目:python3 manage.py runserver
fcj@ubuntu:~/Desktop/code/PythonDemo/MyProject$ python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks... System check identified no issues (0 silenced). You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them. June 15, 2019 - 03:37:00
Django version 2.2.1, using settings 'MyProject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

打开: http://127.0.0.1:8000/

项目运行成功

  • 5解决项目运行时出现的报错:
You have 17 unapplied migration(s). Your project may not work
properly until you apply the migrations for app(s): admin,
auth, contenttypes, sessions.

使用python3 manage.py migrate解决:

fcj@ubuntu:~/Desktop/code/PythonDemo/MyProject$ python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying sessions.0001_initial... OK
fcj@ubuntu:~/Desktop/code/PythonDemo/MyProject$ python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks... System check identified no issues (0 silenced).
June 15, 2019 - 03:41:46
Django version 2.2.1, using settings 'MyProject.settings'
Starting development server at http://127.0.0.1:8000/

Python使用Django创建第一个项目的更多相关文章

  1. python+Django创建第一个项目

    1.首先搭建好环境 1.1 安装pyhton,Linux系统中,python是系统自带的所以就不用安装 1.2 安装Django框架 使用pip安装: pip install django 1.3 检 ...

  2. Django 创建第一个项目(转)

    转自(http://www.runoob.com/django/django-first-app.html) 前面写了不少python程序,由于之前都是作为工具用,所以命令行就足够了,最近写的测试用例 ...

  3. 【3】Django创建第一个项目

    天地所以能长且久者,以其不自生,故能长生. --老子<道德经> 写在前面:Django在学习的过程中,我们会参考官方文档,从两部分进行讲解,第一部分主要是一个入门项目的搭建开发,第二部分是 ...

  4. 吴裕雄--天生自然Django框架开发笔记:Django 创建第一个项目

    Django 管理工具 安装 Django 之后,您现在应该已经有了可用的管理工具 django-admin.可以使用 django-admin 来创建一个项目: 可以来看下django-admin ...

  5. django创建第一个项目helloworld

    环境:centos 7,已安装python 3.6环境 1.安装django并创建django第一个项目 1.1.使用pip安装django# pip install Django或指定安装版本# p ...

  6. Django 创建第一个项目

    创建项目: [root@localhost ~]$ django-admin.py startproject web # web是项目名 [root@localhost ~]$ tree web/ w ...

  7. Angular安装及创建第一个项目

    Angular简介 AngularJS 诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前端JS框架,已经被用于Google的多款产品当中.AngularJ ...

  8. linux下配置python环境 django创建helloworld项目

    linux下配置python环境 1.linux下安装python3 a. 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wget无法下载https链接的文件) yum groupinstal ...

  9. Django 安装、创建第一个项目

    一.版本 Django 版本对应的 Python 版本:   Django 版本 Python 版本 1.8 2.7, 3.2 , 3.3, 3.4, 3.5 1.9, 1.10 2.7, 3.4, ...

随机推荐

  1. .Net 下基于Redlock redis 分布式锁实现

    Redlock-cs (C#/.NET implementation). RedLock.net (C#/.NET implementation). Includes async and lock e ...

  2. [Zjoi2006]三色二叉树(bzoj1864)(洛谷2585)题解

    原题地址:https://www.luogu.org/problemnew/show/P2585 题目大意:可以把一个节点染成三种颜色,父节点和两个子节点(可以有一个)颜色不能相同.求最多(少)能有多 ...

  3. jupyter的补充

    目录 jupyter 的使用 常用命令模式快捷键: 常用编辑模式快捷键: jupyter 的使用 Cells状态分为命令模式和编辑模式,Enter进入编辑模式,ESC进入命令模式,命令模式和编辑模式下 ...

  4. FDQuery Out of memory

    4万行记录 FDQuery查询 Out of memory sql server 可以查询成功 First chance exception at $7505D722. Exception class ...

  5. ex2

    #include <stdio.h> int main() { int days; printf("输入一个整数: \n"); scanf("%d" ...

  6. OpenFOAM——在钝板上分离的层流

    本算例来自<ANSYS Fluid Dynamics Verification Manual>中的VMFL063: Separated Laminar Flow Over a Blunt ...

  7. 拼多多面试真题:如何用 Redis 统计独立用户访问量!

    阅读本文大概需要 2.8 分钟. 作者:沙茶敏碎碎念 众所周至,拼多多的待遇也是高的可怕,在挖人方面也是不遗余力,对于一些工作 3 年的开发,稍微优秀一点的,都给到 30K 的 Offer. 当然,拼 ...

  8. vue.js动态绑定input的checked

    不管<input type='radio checked='true''>  你的checked属性值是true或者false,他都会选中. 其实原理是这样的,复选框里只要有checked ...

  9. 使用gdb调试段错误

    [https://blog.csdn.net/xj9120/article/details/91380074] 1.bt 2.frame number 3.一般是内存问题 4.kill

  10. CMU Advanced DB System - MVCC

    https://zhuanlan.zhihu.com/p/40208895 Mysql的MVCC实现 https://severalnines.com/database-blog/comparing- ...