Django2.0-初步认识

  1. 先操作一发tutorial,循序渐进,一共七节,进行初步认识:https://docs.djangoproject.com/en/2.0/intro/tutorial01/ 重要的事情,我只说一遍,错过了就没了! 不 要 抄 错 代 码 !不 要 乱 加 s.
  2. django-admin.exe/django-admin.py 和${django_project_name}/manage.py的关系:功能是一样的,对project执行一些操作,manage.py会传入当前project的setting.py来设定 DJANGO_SETTINGS_MODULE,并把当前工程放入包放入sys.path;如果你要使用多个settings的话,就用django-admin吧,前提是加入环境变量(什么,你竟然不知道django-admin.exe在哪,它在python安装目录的./Scripts/文件夹里),使用django-admin管理工程比较麻烦!https://docs.djangoproject.com/en/2.0/ref/django-admin/
    要在Python交互式命令下使用django模块的函数,似乎都需要在一个生效的settings.py
    from django.utils import timezone还不会报错,一执行now = timezone.now()
    django.core.exceptions.ImproperlyConfigured: Requested setting USE_TZ, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
    因为它要去读settings.py那个文件!里面设定了时区的!如下
    TIME_ZONE = 'Asia/Chongqing' 什么,你在马耳他? ‘Europe/Malta’ 听说欧洲那里要取消夏令时(DST)了; https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  3. 安装mysql client估计也会遇到问题:pip install mysqlclient 会提示
    error Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: http://landinghub.visualstudio.com/visual-cpp-build-tools 显然你没装VS套件,然后屁颠屁颠去访问这个页面安装C++编译工具,还404!愤怒! 不过先可以升级下pip install –upgrade setuptools,它会更新类似的这些旧链接,然后呢,mysqlclient到底怎么装啊!pip install --only-binary :all: mysqlclient 安装二进制文件就OK啦!https://stackoverflow.com/questions/29846087/microsoft-visual-c-14-0-is-required-unable-to-find-vcvarsall-bat
    不过你有时间电脑也有空间,不妨花个2-3小时装个4G左右的VS2017编译套件,它也会解决类似:
    Failed building wheel for misaka
    Failed to build misaka
    Microsoft Visual C++ 14.0 is required
    Unable to find vcvarsall.bat

    等疑难杂症。
    如果是在Ubuntu下使用pip安装mysqlclient:
    可能会遇到两个问题:a.更新pip后,提示 from pip import main失败:
    解决方法:进入 pip3 的文件夹 sudo vi /usr/bin/pip3 修改:from pip import main 为:from pip._internal import main https://blog.csdn.net/qq_33811662/article/details/80615353
    b.安装mysqlclient提示 mysql_config找不到,“OSError: mysql_config not found” :
    解决方法: apt-get install libmysqlclient-dev python3-dev
    https://blog.csdn.net/wangtaoking1/article/details/51554959

又来
部署部门某个项目:
手册上提示Linux下python3环境下:
在这里插入图片描述
而我,在windows下呀:又祭出StackOverflow:https://stackoverflow.com/questions/454854/no-module-named-mysqldb,首赞这样建议:
在这里插入图片描述然后 pip install mysql-python:
在这里插入图片描述
开始似曾相识了,但还是不清楚python到底有几百种连接数据库的方法【坑】
再然后:https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266
剧终:
error: command 'C:\\Users\\admin\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2
再剧终:
https://blog.csdn.net/qq_28509513/article/details/79134429;
在这里插入图片描述
很好:
在这里插入图片描述
是时候明了了
直接安装二进制文件,py2也可以安装mysqlclient,上面的512赞不是绝对的!!!

  1. 连接数据库:https://docs.djangoproject.com/en/2.0/ref/databases/#mysql-db-api-drivers
  2. settings.py文件解读:https://docs.djangoproject.com/en/2.0/ref/settings/#std:setting-USER
  3. test https://docs.djangoproject.com/en/2.0/intro/tutorial05/
    $ python manage.py test polls
    What happened is this:
    ·python manage.py test polls looked for tests in the polls application
    ·it found a subclass of the django.test.TestCase class
    ·it created a special database for the purpose of testing
    ·it looked for test methods - ones whose names begin with test
    ·in test_was_published_recently_with_future_question it created a Question instance whose pub_date field is 30 days in the future
    ·… and using the assertIs() method, it discovered that its was_published_recently() returns True, though we wanted it to return False

*setup_test_environment() installs a template renderer which will allow us to examine some additional attributes on responses such as response.context that otherwise wouldn’t be available. Note that this method does not setup a test database, so the following will be run against the existing database and the output may differ slightly depending on what questions you already created. You might get unexpected results if your TIME_ZONE in settings.py isn’t correct. If you don’t remember setting it earlier, check it before continuing setup_test_environment() installs a template renderer which will allow us to examine some additional attributes on responses such as response.context that otherwise wouldn’t be available. Note that this method does not setup a test database, so the following will be run against the existing database and the output may differ slightly depending on what questions you already created. You might get unexpected results if your TIME_ZONE in settings.py isn’t correct. If you don’t remember setting it earlier, check it before continuing
In test_future_question, we create a question with a pub_date in the future. The database is reset for each test method, so the first question is no longer there, and so again the index shouldn’t have any questions in it

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值