Criterion

  1. Update frequently less than a year or Irreplaceable
  2. Frequently use in your django project

Python

jinja: https://github.com/pallets/jinja

pillow
awesome-slugify
fuzzywuzzy
markdown

音视频

moviepy

Video editing with Python

Github: https://github.com/Zulko/moviepy

Doc: https://zulko.github.io/moviepy/

MoviePy depends on the Python modules NumPy, Imageio, Decorator, and Proglog, which will be automatically installed during MoviePy’s installation. The software FFMPEG should be automatically downloaded/installed (by imageio) during your first use of MoviePy (installation will take a few seconds).

1
pip install moviepy

Usage

1
2
3
from moviepy.editor import *
audioclip = AudioFileClip("some_videofile.mp4")
audioclip.write_audiofile("some_audiofile.mp3")

爬虫

requests
beautifulsoup4
html5lib
lxml

文档

Pandoc

Universal markup converter

官网:https://pandoc.org/

Github: https://github.com/jgm/pandoc/

下载: https://github.com/jgm/pandoc/releases

使用方法示例:

1
pandoc demo.md -o demo.docx

插件:

1
pip install pandoc-fignos

pandoc-fignos:https://github.com/tomduck/pandoc-fignos

A pandoc filter for numbering figures and figure references.

处理图形的交叉引用

xhtml2pdf

xhtml2pdf is a HTML to PDF converter using Python, the ReportLab Toolkit, html5lib and PyPDF2. It supports HTML5 and CSS 2.1 (and some of CSS 3). It is completely written in pure Python, so it is platform independent.

Github: https://github.com/xhtml2pdf/xhtml2pdf

1
pip install xhtml2pdf

WeasyPrint

The awesome document factory

官网

Github:https://github.com/Kozea/WeasyPrint

Documentation: https://weasyprint.readthedocs.io

Examples: https://weasyprint.org/samples/

1
2
pip install weasyprint
weasyprint https://weasyprint.org/ weasyprint.pdf

出现错误:

1
2
3
4
5
OSError: no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so.2': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e

Win用户此时需要安装GTK3: https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer,并加入环境变量。

测试

单元测试 - 针对程序中最小的功能模块(函数和方法)的测试

测试方法:

- 白盒测试:程序自己写的测试

- 黑盒测试:测试人员或QA,不知道代码实现细节,只关注功能

编写Python单元测试 - 定义类继承TestCase,写测试方法(test_开头)

nose2

1
2
pip install nose2 cov-core
nose2 -v -C

pytest

1
2
3
pip install pytest pytest-cov

pytest -v --cov

Django

The Web framework for perfectionists with deadlines.

Website:

Auth

django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.

https://github.com/pennersr/django-allauth

1
pip install django-allauth

Doc: https://django-allauth.readthedocs.io/en/latest/

Tips: MakeMigration Error on Django - ImportError: cannot import name ‘FieldDoesNotExist’ from ‘django.db.models’ Update your django-allauth:

1
pip install --upgrade django-allauth

social-app-django

https://github.com/python-social-auth/social-app-django

1
$ pip install social-auth-app-django

Python Social Auth是一个提供第三方认证登录的模块。使用这个模块可以让用户以第三方网站的信息进行登录,而无需先注册本网站的用户。

Project documentation is available at http://python-social-auth.readthedocs.org/.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
INSTALLED_APPS = [
#...
'social_django',
]

path('social-auth/', include('social_django.urls', namespace='social'))

e.g.
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'account.authentication.EmailAuthBackend',
'social_core.backends.google.GoogleOAuth2',
]

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'XXX' # API ID
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'XXX' # 密钥

<li class="google"><a href="{% url 'social:begin' 'google-oauth2' %}">Log in with Google</a></li>

django-registration

An extensible user-registration app for Django.

https://github.com/ubernostrum/django-registration

1
pip install django-registration

Doc: https://django-registration.readthedocs.io/en/latest/

django-simple-captcha

Django Simple Captcha is an extremely simple, yet highly customizable Django application to add captcha images to any Django form.

Github: https://github.com/mbi/django-simple-captcha

Doc: http://django-simple-captcha.readthedocs.io/en/latest/

Editor

markdown

django-markdown-editor

Once you have pip, type:

1
$ pip install martor

Markdown Editor plugin for Django (great to use outside default django admin)

img

Github: https://github.com/agusmakmun/django-markdown-editor

Demo: https://python.web.id/posts/create/

Markdownx

Comprehensive Markdown plugin built for Django

django-markdownx preview

Github: https://neutronx.github.io/django-markdownx/

django-summernote

1
pip install django-summernote

django-summernote

Github: https://github.com/summernote/django-summernote

Summernote is a simple WYSIWYG editor.

django-summernote allows you to embed Summernote into Django very handy. Support admin mixins and widgets.

django-ckeditor

1
pip install django-ckeditor

Django admin CKEditor integration.

Github: https://github.com/django-ckeditor/django-ckeditor

Fields & Forms & Templates

django-taggit

https://github.com/jazzband/django-taggit

django-taggit a simpler approach to tagging with Django.

Doc: https://django-taggit.readthedocs.io/en/latest/

django-taggit a simpler approach to tagging with Django. Add "taggit" to your INSTALLED_APPS then just add a TaggableManager to your model and go:

1
2
3
4
5
6
7
8
9
from django.db import models

from taggit.managers import TaggableManager


class Food(models.Model):
# ... fields here

tags = TaggableManager()

Then you can use the API like so:

1
2
3
4
5
6
7
8
9
>>> apple = Food.objects.create(name="apple")
>>> apple.tags.add("red", "green", "delicious")
>>> apple.tags.all()
[<Tag: red>, <Tag: green>, <Tag: delicious>]
>>> apple.tags.remove("green")
>>> apple.tags.all()
[<Tag: red>, <Tag: delicious>]
>>> Food.objects.filter(tags__name__in=["red"])
[<Food: apple>, <Food: cherry>]

Tags will show up for you automatically in forms and the admin.

To further more, in views.py:

1
2
3
4
5
6
7
8
from taggit.models import Tag

def food_list(request, tag_slug=None):
tag = None
if tag_slug:
tag = get_object_or_404(Tag, slug=tag_slug)
object_list = object_list.filter(tags__in=[tag])
...
1
path('tag/<slug:tag_slug>/', views.food_list, name='food_list_by_tag'),
1
2
3
4
5
6
7
8
<!-- <p class="tags">Tags: {{ food.tags.all|join:", " }}</p> -->
<p class="tag">
Tags:
{% for tag in food.tags.all %}
<a href="{% url "food:food_list_by_tag" tag.slug %}">{{ tag.name }}</a>
{% if not forloop.last %}, {% endif %}
{% endfor %}
</p>

django-model-utils

Django model mixins and utilities.

Github: https://github.com/jazzband/django-model-utils

django-upload-multiple-files

Github: https://github.com/kdchang/python-django-upload-multiple-files

django-versatileimagefield

Github: https://github.com/respondcreate/django-versatileimagefield

A drop-in replacement for django’s ImageField that provides a flexible, intuitive and easily-extensible interface for quickly creating new images from the one assigned to the field.

Doc: https://django-versatileimagefield.readthedocs.io/

django-crispy-forms

The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.

Github: https://github.com/django-crispy-forms/django-crispy-forms

django-widget-tweaks

Tweak the form field rendering in templates, not in python-level form definitions. CSS classes and HTML attributes can be altered.

Github: https://github.com/jazzband/django-widget-tweaks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{% load widget_tweaks %}

<!-- change input type (e.g. to HTML5) -->
{% render_field form.search_query type="search" %}

<!-- add/change several attributes -->
{% render_field form.text rows="20" cols="20" title="Hello, world!" %}

<!-- append to an attribute -->
{% render_field form.title class+="css_class_1 css_class_2" %}

<!-- template variables can be used as attribute values -->
{% render_field form.text placeholder=form.text.label %}

<!-- double colon -->
{% render_field form.search_query v-bind::class="{active:isActive}" %}

django-imagekit

pillow

Automated image processing for Django. Currently v4.0

Github: https://github.com/matthewwithanm/django-imagekit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from django.db import models
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill

class Profile(models.Model):
avatar = models.ImageField(upload_to='avatars')
avatar_thumbnail = ImageSpecField(source='avatar',
processors=[ResizeToFill(100, 50)],
format='JPEG',
options={'quality': 60})

profile = Profile.objects.all()[0]
print(profile.avatar_thumbnail.url) # > /media/CACHE/images/982d5af84cddddfd0fbf70892b4431e4.jpg
print(profile.avatar_thumbnail.width) # > 100

sorl-thumbnail

Thumbnails for Django

Getting the code for the latest stable release use ‘pip’.

1
$ pip install sorl-thumbnail

Github: https://github.com/jazzband/sorl-thumbnail

Doc: https://sorl-thumbnail.readthedocs.io/en/latest/

1
2
3
4
INSTALLED_APPS = [
...
'sorl.thumbnail',
]
1
2
3
4
{% load thumbnail %}
{% thumbnail item.image "100x100" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}

Admin Ehancement

django-autocomplete-light

https://github.com/yourlabs/django-autocomplete-light

A fresh approach to autocomplete implementations, specially for Django. Status: v3 stable, 2.x.x stable, 1.x.x deprecated. Please DO regularely ping us with your link at #yourlabs IRC channel

Doc: https://django-autocomplete-light.readthedocs.io/

django-analytical

https://github.com/jazzband/django-analytical

The django-analytical application integrates analytics services into a Django project.

Admin

Slug: https://github.com/voronind/awesome-slugify

simpleui

Github: https://github.com/newpanjing/simpleui

https://simpleui.88cto.com/

A modern theme based on vue+element-ui for django admin.

django-fluent-pages

A smooth, flexible CMS to create the designs you like,built on top of the powerful Django framework.

Features:

  • A fully customizable page hierarchy.
  • Support for multilingual websites.
  • Support for multiple websites in a single database.
  • Fast SEO-friendly page URLs.
  • SEO optimized (meta keywords, description, title, 301-redirects, sitemaps integration).
  • Plugin support for custom page types, which:

https://django-fluent.org/

Github: https://github.com/django-fluent/django-fluent-pages

1
pip install django-fluent-pages

https://github.com/un1t/django-file-resubmit

django-suit

Github: https://github.com/darklow/django-suit

http://djangosuit.com/

Modern theme for Django admin interface.

V2 demo: https://v2.djangosuit.com/admin/login/?next=/admin/

Django-jet

Framework

djangorestframework

Django REST framework is a powerful and flexible toolkit for building Web APIs.

Github: https://github.com/encode/django-rest-framework

https://www.django-rest-framework.org/

For Taggit:

Wagtail

https://wagtail.io/

Wagtail is an open source content management system built on Django, with a strong community and commercial support. It’s focused on user experience, and offers precise control for designers and developers.

https://github.com/wagtail/wagtail

Saleor

https://saleor.io/

Customer-centric e-commerce on a modern stack

A headless, GraphQL-first e-commerce platform delivering ultra-fast, dynamic, personalized shopping experiences. Beautiful online stores, anywhere, on any device.

https://github.com/mirumee/saleor

Search & Filter

django-haystack

Haystack provides modular search for Django. It features a unified, familiar API that allows you to plug in different search backends (such as Solr, Elasticsearch, Whoosh, Xapian, etc.) without having to modify your code.

Github: https://github.com/django-haystack/django-haystack

http://haystacksearch.org/

django-filter

A generic system for filtering Django QuerySets based on user selections

1
pip install django-filter

Github: https://github.com/carltongibson/django-filter

1
2
3
4
5
INSTALLED_APPS = [
...
'django_filters',
...
]
1
2
3
4
5
6
import django_filters

class ProductFilter(django_filters.FilterSet):
class Meta:
model = Product
fields = ['name', 'price', 'manufacturer']
1
2
3
4
5
6
from django_filters import rest_framework as filters

class ProductFilter(filters.FilterSet):
class Meta:
model = Product
fields = ('category', 'in_stock')

django-url-filter

Django URL Filter provides a safe way to filter data via human-friendly URLs.

Easiest way to install this library is by using pip:

1
$ pip install django-url-filter

Github: https://github.com/miki725/django-url-filter

Doc: https://django-url-filter.readthedocs.io/en/latest/

To make example short, it demonstrates Django URL Filter integration with Django REST Framework but it can be used without DRF (see below).

1
2
3
4
5
6
7
8
from url_filter.integrations.drf import DjangoFilterBackend


class UserViewSet(ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
filter_backends = [DjangoFilterBackend]
filter_fields = ['username', 'email']

Alternatively filterset can be manually created and used directly to filter querysets:

1
2
3
4
5
6
7
8
9
10
11
from django.http import QueryDict
from url_filter.filtersets import ModelFilterSet


class UserFilterSet(ModelFilterSet):
class Meta(object):
model = User

query = QueryDict('email__contains=gmail&joined__gt=2015-01-01')
fs = UserFilterSet(data=query, queryset=User.objects.all())
filtered_users = fs.filter()

I18n

django-rosetta

1
pip install django-rosetta

Rosetta is a Django application that eases the translation process of your Django projects

Github: https://github.com/mbi/django-rosetta

Doc: https://django-rosetta.readthedocs.io/

django-parler

Easily translate “cheese omelet” into “omelette au fromage”.

The package can be installed using:

1
pip install django-parler

Github: https://github.com/django-parler/django-parler

Doc: https://django-parler.readthedocs.io/en/stable/

1
2
3
INSTALLED_APPS += (
'parler',
)

django-modeltranslation

ranslates Django models using a registration approach.

Github: Thttps://github.com/deschler/django-modeltranslation

Doc: https://django-modeltranslation.readthedocs.org/en/latest

django-autotranslate

A simple Django app to automatically translate the pot (.po) files generated by django’s makemessages command using google translate.

Github: https://github.com/ankitpopli1891/django-autotranslate

Doc: https://ankitpopli1891.github.io/django-autotranslate/

1
pip install django-autotranslate

Add 'autotranslate' to your INSTALLED_APPS setting.

1
2
3
4
INSTALLED_APPS = (
...
'autotranslate',

1
python manage.py translate_messages
1
2
3
4
# default: 'autotranslate.services.GoSlateTranslatorService'
# pip install google-api-python-client
AUTOTRANSLATE_TRANSLATOR_SERVICE = 'autotranslate.services.GoogleAPITranslatorService'
GOOGLE_TRANSLATE_KEY = '<google-api-key>'

Conf

django-hosts

https://github.com/jazzband/django-hosts

1
pip install django-hosts

You can find the full docs here: django-hosts.rtfd.org

Dynamic and static host resolving for Django. Maps hostnames to URLconfs.

For example, if you own example.com but want to serve specific content at api.example.com and beta.example.com, add the following to a hosts.py file:

1
2
3
4
5
6
from django_hosts import patterns, host

host_patterns = patterns('path.to',
host(r'api', 'api.urls', name='api'),
host(r'beta', 'beta.urls', name='beta'),
)

django-debug-toolbar

Github: https://github.com/jazzband/django-debug-toolbar

A configurable set of panels that display various debug information about the current request/response.

Doc: https://django-debug-toolbar.readthedocs.io/.

django-appconf

A helper class for handling configuration defaults of packaged Django apps gracefully.

GIthub: https://github.com/django-compressor/django-appconf

Doc: https://django-appconf.readthedocs.io/

django-redis

Full featured redis cache backend for Django.

Github: https://github.com/jazzband/django-redis

Install with pip:

1
$ python -m pip install django-redis

Configure as cache backend

To start using django-redis, you should change your Django cache settings to something like:

1
2
3
4
5
6
7
8
9
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}

Projects

cookiecutter-django

Github: https://github.com/pydanny/cookiecutter-django

Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

First, get Cookiecutter. Trust me, it’s awesome:

1
$ pip install "cookiecutter>=1.7.0"

Now run it against this repo:

1
$ cookiecutter https://github.com/pydanny/cookiecutter-django

Chatbot_CN]

Github: https://github.com/charlesXu86/Chatbot_CN

Chatbot_CN 是一个基于第三代对话系统的多轮对话机器人项目,旨在于开发一个结合规则系统、深度学习、强化学习、知识图谱、多轮对话策略管理的 聊天机器人,目前随着时间的慢慢发展,从最初的一个 Chatbot_CN 项目,发展成了一个 Chatbot_* 的多个项目。目前已经包含了在多轮任务型对话的场景中,基于话术(Story)、知识图谱(K-G)、端到端对话(E2E)。目的是为了实现一个可以快速切换场景、对话灵活的任务型机器人。 同时,Chatbot_CN 不仅仅是一个对话系统,而是一套针对客服场景下的完整人工智能解决方案。对话是解决方案的核心和最重要一环,但不仅限于对话,还包括智能决策,智能调度,智能预测,智能推荐等

django-wiki

https://demo.django-wiki.org/

A wiki system with complex functionality for simple integration and a superb interface. Store your knowledge with style: Use django models.

django_quiz

This is a configurable quiz app for Django.

Here is an example website

Scrapyd-Django-Template

Basic setup to run ScrapyD + Django and save it in Django Models. You can be up and running in just a few minutes

Img2VecCosSim-Django-Pytorch

Extract a feature vector for any image and find the cosine similarity for comparison using Pytorch. I have used ResNet-18 to extract the feature vector of images. Finally a Django app is developed to input two images and to find the cosine similarity.

vermouth

A torrent site written in the python language & douban scraper

www.gulu.today/

Outdated

Resources

Github Django Resources:

Python:

Books:

Website:

  • Penjee: https://penjee.com/

    Penjee is a place where you can learn how to code with the python language. Start right away with our tutorial!