zoukankan      html  css  js  c++  java
  • 树莓派下安装Django环境

    Django是Python下的一款网络服务器框架。

    Python下有许多款不同的框架。

    Django是重量级选手中最有代表性的一位。

    许多成功的网站和APP都基于Django。

    安装pip

    sudo apt-get install python-pip python-dev build-essential
    sudo pip install --upgrade pip
    

    安装Django

    sudo pip install django
    

    安装成功之后我们可以进入python命令行查看django版本:

    pi@raspberrypi:~ $ python
    
    import django
    print(django.VERSION)
    

    安装过程中如果因为下载太慢失败的话,可以更改pip源为国内阿里源,具体内容见我前边写的树莓派初始设置

    安装过程中遇到报错:

    ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
    

    在这里插入图片描述
    因为树莓派默认的python是2.7版本,所以pip默认也是给python2安装的。

    DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. 
    Please upgrade your Python as Python 2.7 won't be maintained after that date. 
    A future version of pip will drop support for Python 2.7. 
    More details about Python 2 support in pip, can be found at 
    https://pip.pypa.io/en/latest/development/release-process/#python-2-support                                                                                                            
    

    不过树莓派有自带的python3.5版本,有两种解决方案:

    第一种是将python的软链接指向python3.5,不过这种方案会虽然当前不会有问题,但是后续的开发过程中可能会遇到无数莫名其妙的错误,而且很难解决,踩坑实证,如果有哪位大佬找到了完美将树莓派默认python改为python3的方法,恳请赐教。

    第二种方案就是,直接为python3安装Django,简单方便快捷:

    sudo pip3 install django
    

    启动

    可以使用下面的命令创建一个Django项目:

    django-admin startproject Candy_Dumplings
    

    可以用tree命令看到起文件结构:

    tree Candy_Dumplings
    

    在这里插入图片描述
    然后进入到我们项目文件之后,可以创建相应的APP:

    python3 manage.py startapp webpage
    

    好了Y( ^ o ^ )Y,树莓派的Django环境搭建基本上就到这里就OK了。

  • 相关阅读:
    spring boot所有配置
    Hibernate validator的一些额外特性
    相似序列搜索
    时间序列异常检测
    基于结构的距离度量
    jupyterlab的启动404error问题
    爬虫-Chrome-问题1
    厘清重要概念的内涵与外延
    六)定时任务持久化
    公钥私钥
  • 原文地址:https://www.cnblogs.com/AlexKing007/p/12338115.html
Copyright © 2011-2022 走看看