一 必要环境安装

  • 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/

最新文章

  1. UVA 10795 新汉诺塔问题
  2. 【WP开发】手电筒
  3. 边工作边刷题:70天一遍leetcode: day 81
  4. linphone3.4.0代码分析
  5. 屏幕序列Screen Sequences
  6. CSS3—六边形
  7. Linux命令(1):cd命令
  8. jQuery滚动条插件 – jquery.slimscroll.js
  9. C# 线程同步之排它锁/Monitor监视器类
  10. EF Unit Of Work
  11. javaWeb学习总结(1)- Tomcat服务器学习和使用(2)
  12. C语言--第0周作业
  13. Kafka分区与消费者的关系
  14. ASP.NET 管道
  15. 使用PHP+MySql+Ajax+jQuery实现省市区三级联动功能
  16. (转)mtr命令详解诊断网络路由
  17. Linux系统上传文件与下载文件命令
  18. JVM结构及堆的划分
  19. JavaScript中的构造函数 renturn
  20. 德哥PostgreSQL学习资料汇总(转)

热门文章

  1. kuma 学习一 minikube 安装
  2. 使用haproxy 2.0 prometheus metrics 监控系统状态
  3. nginx 访问控制之deny allow
  4. Java解决java.io.FileNotFoundException: E:\work\work (拒绝访问。)
  5. cgdsR 下载TCGA数据
  6. HGNC数据库 HUGO基因命名委员会
  7. 联想M7216NWA墨粉清零:
  8. MySQL悲观
  9. IDEA光标类的操作
  10. 泡泡一分钟:Real-Time Vehicle Detection from Short-Range Aerial Image with Compressed MobileNet