Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/img/logo-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/logo-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/img/logo.png
Binary file not shown.
112 changes: 63 additions & 49 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
</style>

<p class="badges" height=20px>
<div class="badges">
<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>

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

---

<p>
<h1 style="position: absolute;
width: 1px;
height: 1px;
Expand All @@ -41,8 +40,8 @@
clip: rect(0,0,0,0);
border: 0;">Django REST Framework</h1>

<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">
</p>
![Django REST Framework](img/logo-light.png#only-light)
![Django REST Framework](img/logo-dark.png#only-dark)

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

Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand Down
Binary file added docs/theme/img/favicon.ico
Binary file not shown.
Binary file added docs/theme/img/grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/theme/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions docs/theme/stylesheets/extra.css
Original file line number Diff line number Diff line change
@@ -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;
}
56 changes: 47 additions & 9 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion requirements/requirements-documentation.txt
Original file line number Diff line number Diff line change
@@ -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
Loading