diff --git a/docs/img/logo-dark.png b/docs/img/logo-dark.png new file mode 100644 index 0000000000..43684296e1 Binary files /dev/null and b/docs/img/logo-dark.png differ diff --git a/docs/img/logo-light.png b/docs/img/logo-light.png new file mode 100644 index 0000000000..8a121d72a1 Binary files /dev/null and b/docs/img/logo-light.png differ diff --git a/docs/img/logo.png b/docs/img/logo.png deleted file mode 100644 index 73de34f4b8..0000000000 Binary files a/docs/img/logo.png and /dev/null differ diff --git a/docs/index.md b/docs/index.md index 3888880fad..fb6d61444d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,7 @@ } -
+
--- -
-
+
+
Django REST framework is a powerful and flexible toolkit for building Web APIs.
@@ -79,27 +78,35 @@ The following packages are optional:
Install using `pip`, including any optional packages you want...
- pip install djangorestframework
- pip install markdown # Markdown support for the browsable API.
- pip install django-filter # Filtering support
+```bash
+pip install djangorestframework
+pip install markdown # Markdown support for the browsable API.
+pip install django-filter # Filtering support
+```
...or clone the project from github.
- git clone https://github.com/encode/django-rest-framework
+```bash
+git clone https://github.com/encode/django-rest-framework
+```
Add `'rest_framework'` to your `INSTALLED_APPS` setting.
- INSTALLED_APPS = [
- ...
- 'rest_framework',
- ]
+```python
+INSTALLED_APPS = [
+ # ...
+ "rest_framework",
+]
+```
If you're intending to use the browsable API you'll probably also want to add REST framework's login and logout views. Add the following to your root `urls.py` file.
- urlpatterns = [
- ...
- path('api-auth/', include('rest_framework.urls'))
- ]
+```python
+urlpatterns = [
+ # ...
+ path("api-auth/", include("rest_framework.urls"))
+]
+```
Note that the URL path can be whatever you want.
@@ -111,44 +118,51 @@ We'll create a read-write API for accessing information on the users of our proj
Any global settings for a REST framework API are kept in a single configuration dictionary named `REST_FRAMEWORK`. Start off by adding the following to your `settings.py` module:
- REST_FRAMEWORK = {
- # Use Django's standard `django.contrib.auth` permissions,
- # or allow read-only access for unauthenticated users.
- 'DEFAULT_PERMISSION_CLASSES': [
- 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
- ]
- }
+```python
+REST_FRAMEWORK = {
+ # Use Django's standard `django.contrib.auth` permissions,
+ # or allow read-only access for unauthenticated users.
+ "DEFAULT_PERMISSION_CLASSES": [
+ "rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly"
+ ]
+}
+```
Don't forget to make sure you've also added `rest_framework` to your `INSTALLED_APPS`.
We're ready to create our API now.
Here's our project's root `urls.py` module:
- from django.urls import path, include
- from django.contrib.auth.models import User
- from rest_framework import routers, serializers, viewsets
-
- # Serializers define the API representation.
- class UserSerializer(serializers.HyperlinkedModelSerializer):
- class Meta:
- model = User
- fields = ['url', 'username', 'email', 'is_staff']
-
- # ViewSets define the view behavior.
- class UserViewSet(viewsets.ModelViewSet):
- queryset = User.objects.all()
- serializer_class = UserSerializer
-
- # Routers provide an easy way of automatically determining the URL conf.
- router = routers.DefaultRouter()
- router.register(r'users', UserViewSet)
-
- # Wire up our API using automatic URL routing.
- # Additionally, we include login URLs for the browsable API.
- urlpatterns = [
- path('', include(router.urls)),
- path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
- ]
+```python
+from django.urls import path, include
+from django.contrib.auth.models import User
+from rest_framework import routers, serializers, viewsets
+
+
+# Serializers define the API representation.
+class UserSerializer(serializers.HyperlinkedModelSerializer):
+ class Meta:
+ model = User
+ fields = ["url", "username", "email", "is_staff"]
+
+
+# ViewSets define the view behavior.
+class UserViewSet(viewsets.ModelViewSet):
+ queryset = User.objects.all()
+ serializer_class = UserSerializer
+
+
+# Routers provide an easy way of automatically determining the URL conf.
+router = routers.DefaultRouter()
+router.register(r"users", UserViewSet)
+
+# Wire up our API using automatic URL routing.
+# Additionally, we include login URLs for the browsable API.
+urlpatterns = [
+ path("", include(router.urls)),
+ path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
+]
+```
You can now open the API in your browser at [http://127.0.0.1:8000/](http://127.0.0.1:8000/), and view your new 'users' API. If you use the login control in the top right corner you'll also be able to add, create and delete users from the system.
diff --git a/docs/theme/img/favicon.ico b/docs/theme/img/favicon.ico
new file mode 100644
index 0000000000..917892ad57
Binary files /dev/null and b/docs/theme/img/favicon.ico differ
diff --git a/docs/theme/img/grid.png b/docs/theme/img/grid.png
new file mode 100644
index 0000000000..878c3ed5c1
Binary files /dev/null and b/docs/theme/img/grid.png differ
diff --git a/docs/theme/img/logo.png b/docs/theme/img/logo.png
new file mode 100644
index 0000000000..f2a5beea9a
Binary files /dev/null and b/docs/theme/img/logo.png differ
diff --git a/docs/theme/stylesheets/extra.css b/docs/theme/stylesheets/extra.css
new file mode 100644
index 0000000000..e959b7bee5
--- /dev/null
+++ b/docs/theme/stylesheets/extra.css
@@ -0,0 +1,81 @@
+:root > * {
+ /* primary */
+ --md-primary-fg-color: #2c2c2c;
+ --md-primary-fg-color--light: #a8a8a8;
+ --md-primary-fg-color--dark: #181818;
+ /* accent */
+ --md-accent-fg-color: #c50d0d;
+ --md-accent-fg-color--light: #ff8f8f;
+ --md-accent-fg-color--dark: #A30000;
+
+ /* Style links */
+ --md-typeset-a-color: var(--md-typeset-color);
+}
+
+/* Dark theme customisation */
+[data-md-color-scheme="slate"]
+{}
+
+.md-header {
+ border-top: 5px solid var(--md-accent-fg-color--dark);
+}
+
+body hr {
+ border-top: 1px dotted var(--md-accent-fg-color--dark);
+}
+
+.badges {
+ display: flex;
+ flex-direction: row-reverse;
+ align-content: end;
+ gap: 8px;
+}
+
+/* Cutesy quote styling */
+[dir="ltr"] .md-typeset blockquote {
+ font-family: Georgia, serif;
+ font-size: 18px;
+ font-style: italic;
+ margin: 0.25em 0;
+ padding: 0.25em 40px;
+ line-height: 1.45;
+ position: relative;
+ color: var(--md-typeset-color);
+ border-left: none;
+}
+
+[dir="ltr"] .md-typeset blockquote:before {
+ display: block;
+ content: "\201C";
+ font-size: 80px;
+ position: absolute;
+ left: -10px;
+ top: -20px;
+ color: #7a7a7a;
+}
+
+[dir="ltr"] .md-typeset blockquote p:last-child {
+ color: #999999;
+ font-size: 14px;
+ display: block;
+ margin-top: 5px;
+}
+
+.md-typeset a {
+ color: var(--md-accent-fg-color--dark);
+}
+
+/* Replacement for `body { background-attachment: fixed; }`, which
+ has performance issues when scrolling on large displays. */
+body::before {
+ content: ' ';
+ position: fixed;
+ width: 100%;
+ height: 100%;
+ top: 0;
+ left: 0;
+ background-color: #f8f8f8;
+ background: url(../img/grid.png) repeat-x;
+ will-change: transform;
+ z-index: -1;
+}
\ No newline at end of file
diff --git a/mkdocs.yml b/mkdocs.yml
index a544be8f4f..eafd91a47c 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -5,13 +5,57 @@ site_description: Django REST framework - Web APIs for Django
repo_url: https://github.com/encode/django-rest-framework
theme:
- name: mkdocs
- custom_dir: docs_theme
+ name: material
+ favicon: theme/img/favicon.ico
+ logo: theme/img/logo.png
+ palette:
+ - media: "(prefers-color-scheme)"
+ primary: custom
+ accent: custom
+ toggle:
+ icon: material/brightness-auto
+ name: "Switch to light mode"
+ - media: "(prefers-color-scheme: light)"
+ scheme: default
+ primary: custom
+ accent: custom
+ toggle:
+ icon: material/brightness-7
+ name: "Switch to dark mode"
+ - media: "(prefers-color-scheme: dark)"
+ scheme: slate
+ primary: custom
+ accent: custom
+ toggle:
+ icon: material/brightness-4
+ name: "Switch to system preference"
+ features:
+ - content.tabs.link
+ - content.code.annotate
+ - content.code.copy
+ - navigation.tabs
+ - navigation.instant
+ - navigation.instant.prefetch
+ - navigation.instant.progress
+ - navigation.path
+ - navigation.sections
+ - navigation.top
+ - navigation.tracking
+ - search.suggest
+ - toc.follow
+
+extra_css:
+ - theme/stylesheets/extra.css
markdown_extensions:
- admonition
- toc:
- anchorlink: True
+ permalink: true
+ - pymdownx.highlight:
+ pygments_lang_class: true
+ - pymdownx.inlinehilite
+ - pymdownx.snippets
+ - pymdownx.superfences
nav:
- Home: 'index.md'
@@ -86,9 +130,3 @@ nav:
- 'Kickstarter Announcement': 'community/kickstarter-announcement.md'
- 'Mozilla Grant': 'community/mozilla-grant.md'
- 'Jobs': 'community/jobs.md'
-
-extra_css:
- - css/copy-button.css
-
-extra_javascript:
- - js/copy-button.js
diff --git a/requirements/requirements-documentation.txt b/requirements/requirements-documentation.txt
index 2cf936ef38..c7e07acb3e 100644
--- a/requirements/requirements-documentation.txt
+++ b/requirements/requirements-documentation.txt
@@ -1,5 +1,5 @@
# MkDocs to build our documentation.
mkdocs==1.6.0
-
+mkdocs-material[imaging]==9.7.0
# pylinkvalidator to check for broken links in documentation.
pylinkvalidator==0.3