Django-PythonWeb框架的安装与使用

Django-中文名:姜戈,采用MVC模型的Web框架。

Django有一个管理工具,叫Django-admin.py,可以通过它来创建项目,其实类似Scrapy框架。

环境:Win10;Python3.7

有几种安装方式:

1、使用pip安装

比如当前Django最新版为2.1.4,我使用最简陋的方式:

Microsoft Windows [版本 10.0.17134.471]
(c) 2018 Microsoft Corporation。保留所有权利。

C:\Users\admin>pip install Django==2.1.4
Collecting Django==2.1.4
  Downloading https://files.pythonhosted.org/packages/fd/9a/0c028ea0fe4f5803dda1a7afabeed958d0c8b79b0fe762ffbf728db3b90d/Django-2.1.4-py3-none-any.whl (7.3MB)
    100% |████████████████████████████████| 7.3MB 553kB/s
Requirement already satisfied: pytz in e:\python\python37\lib\site-packages (from Django==2.1.4) (2018.5)
Installing collected packages: Django
Successfully installed Django-2.1.4

直接装在了C盘中,可以根据需要进到其他目录安装

2、使用源码安装,git上下载Django项目,手动编译安装

执行(未尝试)

python setup.py install 

此时如果安装成功,命令行执行

E:\>django-admin

Type 'django-admin help <subcommand>' for help on a specific subcommand.

Available subcommands:

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    runserver
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).

以前版本可能是执行django-admin.py,但最新版本使用django-admin(已经加入到系统参数中,所以到处可以执行)

创建一个Django项目,使用命令

E:\>django-admin startproject HelloWorld

这样就将HelloWorld(向程序员前辈们致敬)创建好了,在E盘目录下

很眼熟,翻出Scrapy的创建项目方式:

scrapy startproject tutorial

果然是工具+startproject+项目名

此时创建完成,然后将项目运行吧,进入到项目目录下,执行命令,使用8000端口:

E:\>cd HelloWorld

E:\HelloWorld>python manage.py runserver 0.0.0.0:8000
Performing system checks...

System check identified no issues (0 silenced).

You have 15 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.
December 14, 2018 - 09:00:27
Django version 2.1.4, using settings 'HelloWorld.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CTRL-BREAK.
[14/Dec/2018 09:00:39] "GET / HTTP/1.1" 200 16348
[14/Dec/2018 09:00:39] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[14/Dec/2018 09:00:39] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564
[14/Dec/2018 09:00:39] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
[14/Dec/2018 09:00:39] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
Not Found: /favicon.ico
[14/Dec/2018 09:00:39] "GET /favicon.ico HTTP/1.1" 404 1976

启动如下:

官方文档地址:https://www.djangoproject.com/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值