Django
的官网文档整理了一下,这其中不包括太多的代码案例,只是把常用的知识点、核心内容和开发常见的问题汇总一下。主要针对新手、开发人员使用(看过源码的大佬请忽略)。
官方文档带你入门Django
:https://docs.djangoproject.com/en/3.1/intro/,这部分文档介绍挺详细,而且对于新手没有太大的难度,易于理解,代码完整
下面是我总结的一些知识点
,这些内容也包含在官方文档
中,但这是我认为新手可能经常忽略的部分。
https://docs.djangoproject.com/en/3.1/intro/tutorial01/
https://docs.djangoproject.com/en/3.1/intro/tutorial05/
创建测试类—test.py
应用程序测试的常规位置是在应用程序的 tests.py文件中。测试系统将自动在其中找对应的测试类
。
import datetime
from django.test import TestCase
from django.utils import timezone
from .models import Question
class QuestionModelTests(TestCase):
def test_was_published_recently_with_future_question(self):
"""
was_published_recently() returns False for questions whose pub_date
is in the future.
"""
time = timezone.now() + datetime.timedelta(days=30)
future_question = Question(pub_date=time)
self.assertIs(future_question.was_published_recently(), False)
def test_was_published_recently_with_old_question(self):
"""
was_published_recently() returns False for questions whose pub_date
is older than 1 day.
"""
time = timezone.now() - datetime.timedelta(days=1, seconds=1)
old_question = Question(pub_date=time)
self.assertIs(old_question.was_published_recently(), False)
`
运行测试
python manage.py test app名称
https://docs.djangoproject.com/en/3.1/intro/reusable-apps/
https://docs.djangoproject.com/en/3.1/intro/contributing/
https://docs.djangoproject.com/en/3.1/topics/install/
https://docs.djangoproject.com/en/3.1/topics/db/
多数据的使用: https://docs.djangoproject.com/en/3.1/topics/db/multi-db/
https://docs.djangoproject.com/en/3.1/topics/http/
中间件: https://docs.djangoproject.com/en/3.1/topics/http/middleware/
https://docs.djangoproject.com/en/3.1/topics/class-based-views/
https://docs.djangoproject.com/en/3.1/topics/forms/
https://docs.djangoproject.com/en/3.1/topics/templates/
https://docs.djangoproject.com/en/3.1/topics/migrations/
https://docs.djangoproject.com/en/3.1/topics/testing/
https://docs.djangoproject.com/en/3.1/topics/email/
https://docs.djangoproject.com/en/3.1/topics/i18n/
https://docs.djangoproject.com/en/3.1/faq/
https://docs.djangoproject.com/en/3.1/ref/