Skip to content

Commit 190aae3

Browse files
browniebrokeauvipyCopilot
authored
Switch to mkdocs material theme for documentation (#9849)
* Switch to mkdocs material theme * Add logo * Style badges on homepage * Basic dark theme * Enable a few theme features * Customise large logo for dark theme * CSS tweaks * Add background grid back * Switch to mkdocs material theme * Add logo * Style badges on homepage * Basic dark theme * Add syntax highlighting to code snippets * Convert homepage snippets to code fences * Update homepage logos * Move mkdocs-material to pyproject.toml docs group * Keep existing syntax highlighting * Remove old docs_theme folder * Tweak syntax highlighting colors on dark theme * Add readthedocs config file * Fix end of file empty lines * Upgrade pip during install * Remove custom styling for .prettyprint * Remove .prettyprint border entirely * Make tabs sticky in navbar * Merge page ToC with navigation * Tweak colors for more accessible contrast * Add Figma file for the logos * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Adjust styles for badges * Enable content tabs for OS specific instructions https://squidfunk.github.io/mkdocs-material/reference/content-tabs/ * Add icons for content tabs * Standardize on .venv for virtualenv name in docs * Add note about bash for Windows --------- Co-authored-by: Asif Saif Uddin {"Auvi":"ΰ¦…ΰ¦­ΰ¦Ώ"} <auvipy@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 40e77f0 commit 190aae3

33 files changed

+321
-7719
lines changed

β€Ž.gitattributesβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/theme/src/drf-logos.fig filter=lfs diff=lfs merge=lfs -text

β€Ž.gitignoreβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*.pyc
22
*.db
33
*~
4-
.*
54
*.py.bak
65

76

@@ -14,6 +13,8 @@
1413
/env/
1514
MANIFEST
1615
coverage.*
16+
.coverage
17+
.cache/
1718

1819
!.github
1920
!.gitignore

β€Ž.readthedocs.yamlβ€Ž

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the OS, Python version, and other tools you might need
8+
build:
9+
os: ubuntu-24.04
10+
tools:
11+
python: "3.13"
12+
jobs:
13+
install:
14+
- pip install --upgrade pip
15+
- pip install -e . --group docs
16+
17+
# Build documentation with Mkdocs
18+
mkdocs:
19+
configuration: mkdocs.yml

β€Ždocs/img/logo-dark.pngβ€Ž

37.8 KB
Loading

β€Ždocs/img/logo-light.pngβ€Ž

35.8 KB
Loading

β€Ždocs/img/logo.pngβ€Ž

-40.6 KB
Binary file not shown.

β€Ždocs/index.mdβ€Ž

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
</style>
1919

20-
<p class="badges" height=20px>
20+
<div class="badges">
2121
<iframe src="https://ghbtns.com/github-btn.html?user=encode&amp;repo=django-rest-framework&amp;type=watch&amp;count=true" class="github-star-button" allowtransparency="true" frameborder="0" scrolling="0" width="110px" height="20px"></iframe>
2222

2323
<a href="https://github.com/encode/django-rest-framework/actions/workflows/main.yml">
@@ -27,11 +27,10 @@
2727
<a href="https://pypi.org/project/djangorestframework/">
2828
<img src="https://img.shields.io/pypi/v/djangorestframework.svg" class="status-badge">
2929
</a>
30-
</p>
30+
</div>
3131

3232
---
3333

34-
<p>
3534
<h1 style="position: absolute;
3635
width: 1px;
3736
height: 1px;
@@ -41,8 +40,8 @@
4140
clip: rect(0,0,0,0);
4241
border: 0;">Django REST Framework</h1>
4342

44-
<img alt="Django REST Framework" title="Logo by Jake 'Sid' Smith" src="img/logo.png" width="600px" style="display: block; margin: 0 auto 0 auto">
45-
</p>
43+
![Django REST Framework](img/logo-light.png#only-light)
44+
![Django REST Framework](img/logo-dark.png#only-dark)
4645

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

@@ -79,27 +78,35 @@ The following packages are optional:
7978

8079
Install using `pip`, including any optional packages you want...
8180

82-
pip install djangorestframework
83-
pip install markdown # Markdown support for the browsable API.
84-
pip install django-filter # Filtering support
81+
```bash
82+
pip install djangorestframework
83+
pip install markdown # Markdown support for the browsable API.
84+
pip install django-filter # Filtering support
85+
```
8586

8687
...or clone the project from github.
8788

88-
git clone https://github.com/encode/django-rest-framework
89+
```bash
90+
git clone https://github.com/encode/django-rest-framework
91+
```
8992

9093
Add `'rest_framework'` to your `INSTALLED_APPS` setting.
9194

92-
INSTALLED_APPS = [
93-
...
94-
'rest_framework',
95-
]
95+
```python
96+
INSTALLED_APPS = [
97+
# ...
98+
"rest_framework",
99+
]
100+
```
96101

97102
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.
98103

99-
urlpatterns = [
100-
...
101-
path('api-auth/', include('rest_framework.urls'))
102-
]
104+
```python
105+
urlpatterns = [
106+
# ...
107+
path("api-auth/", include("rest_framework.urls"))
108+
]
109+
```
103110

104111
Note that the URL path can be whatever you want.
105112

@@ -111,44 +118,51 @@ We'll create a read-write API for accessing information on the users of our proj
111118

112119
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:
113120

114-
REST_FRAMEWORK = {
115-
# Use Django's standard `django.contrib.auth` permissions,
116-
# or allow read-only access for unauthenticated users.
117-
'DEFAULT_PERMISSION_CLASSES': [
118-
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
119-
]
120-
}
121+
```python
122+
REST_FRAMEWORK = {
123+
# Use Django's standard `django.contrib.auth` permissions,
124+
# or allow read-only access for unauthenticated users.
125+
"DEFAULT_PERMISSION_CLASSES": [
126+
"rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly"
127+
]
128+
}
129+
```
121130

122131
Don't forget to make sure you've also added `rest_framework` to your `INSTALLED_APPS`.
123132

124133
We're ready to create our API now.
125134
Here's our project's root `urls.py` module:
126135

127-
from django.urls import path, include
128-
from django.contrib.auth.models import User
129-
from rest_framework import routers, serializers, viewsets
130-
131-
# Serializers define the API representation.
132-
class UserSerializer(serializers.HyperlinkedModelSerializer):
133-
class Meta:
134-
model = User
135-
fields = ['url', 'username', 'email', 'is_staff']
136-
137-
# ViewSets define the view behavior.
138-
class UserViewSet(viewsets.ModelViewSet):
139-
queryset = User.objects.all()
140-
serializer_class = UserSerializer
141-
142-
# Routers provide an easy way of automatically determining the URL conf.
143-
router = routers.DefaultRouter()
144-
router.register(r'users', UserViewSet)
145-
146-
# Wire up our API using automatic URL routing.
147-
# Additionally, we include login URLs for the browsable API.
148-
urlpatterns = [
149-
path('', include(router.urls)),
150-
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
151-
]
136+
```python
137+
from django.urls import path, include
138+
from django.contrib.auth.models import User
139+
from rest_framework import routers, serializers, viewsets
140+
141+
142+
# Serializers define the API representation.
143+
class UserSerializer(serializers.HyperlinkedModelSerializer):
144+
class Meta:
145+
model = User
146+
fields = ["url", "username", "email", "is_staff"]
147+
148+
149+
# ViewSets define the view behavior.
150+
class UserViewSet(viewsets.ModelViewSet):
151+
queryset = User.objects.all()
152+
serializer_class = UserSerializer
153+
154+
155+
# Routers provide an easy way of automatically determining the URL conf.
156+
router = routers.DefaultRouter()
157+
router.register(r"users", UserViewSet)
158+
159+
# Wire up our API using automatic URL routing.
160+
# Additionally, we include login URLs for the browsable API.
161+
urlpatterns = [
162+
path("", include(router.urls)),
163+
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
164+
]
165+
```
152166

153167
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.
154168

β€Ždocs/theme/img/logo.pngβ€Ž

20.5 KB
Loading

0 commit comments

Comments
Β (0)