Skip to content

Commit b7e7833

Browse files
committed
Update readme and docs/index.
1 parent bd62c27 commit b7e7833

2 files changed

Lines changed: 78 additions & 16 deletions

File tree

README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<a href="https://django-fbv.adamghill.com"><h1 align="center">django-fbv</h1></a>
2+
<a href="https://django-fbv.adamghill.com"><h1 align="center">django-fbv 🕶️</h1></a>
33
</p>
44
<p align="center">Utilities to make Django function-based views cleaner, more efficient, and better tasting. 💥</p>
55

@@ -9,18 +9,51 @@
99

1010
📖 Complete documentation: https://django-fbv.adamghill.com
1111

12-
📦 Package located at https://pypi.org/project/django-fbv/
12+
## Why? 🤔
1313

14-
## Features
14+
The Django community has two ways to write views: [class-based](https://docs.djangoproject.com/en/stable/topics/class-based-views/) and [function-based](https://docs.djangoproject.com/en/stable/topics/http/views/). One benefit of function-based views is that the input of a `HttpRequest` and the `HttpResponse` output is explicit.
1515

16-
## Features
16+
`django-fbv` reduces the boilerplate code required when using function-based views. It also leverages _locality of behavior_ -- the name of the template is clearly associated to the view, instead of being part of the return statement.
17+
18+
Instead of this:
19+
20+
```python
21+
# sample_app/views.py
22+
from django.shortcuts import render
23+
24+
def regular_function_based_view(request):
25+
return render(request, "template_name.html", {"data": 123})
26+
```
27+
28+
You can write this:
29+
30+
```python
31+
# sample_app/views.py
32+
from fbv.decorators import render_html
33+
34+
@render_html("template_name.html")
35+
def django_fbv_view(request):
36+
return {"data": 123}
37+
```
38+
39+
```{note}
40+
If you want a more detailed critique of class-based views, I recommend reading [Django Views the Right Way](https://spookylukey.github.io/django-views-the-right-way/).
41+
```
42+
43+
## Installation ⚙️
44+
45+
`pip install django-fbv` OR `uv add django-fbv`
46+
47+
The [decorators](decorators.md) and [views](views.md) can be used by just importing them. The middleware [needs to be installed](https://django-fbv.adamghill.com/en/latest/middleware/#installation).
48+
49+
## Features 🤩
1750

1851
### Decorators
1952

2053
- [`fbv.decorators.render_html`](https://django-fbv.adamghill.com/en/latest/decorators/#render-html): renders a view as HTML with the specified template
2154
- [`fbv.decorators.render_view`](https://django-fbv.adamghill.com/en/latest/decorators/#render-view): renders a view as a content type with the specified template
2255
- [`fbv.decorators.render_json`](https://django-fbv.adamghill.com/en/latest/decorators/#render-json):
23-
renders dictionaries, Django Models, or Django QuerySets as a JSON response
56+
renders dictionaries, Django `Model`, or Django `QuerySet` as a `JSON` response
2457

2558
### Views
2659

@@ -34,4 +67,7 @@ renders dictionaries, Django Models, or Django QuerySets as a JSON response
3467

3568
- [`fbv.middleware.RequestMethodMiddleware`](https://django-fbv.adamghill.com/en/latest/middleware/): adds a boolean property to the `request` for the current request's HTTP method
3669

37-
Read all of the documentation at https://django-fbv.adamghill.com/.
70+
## Prior art 🖼️
71+
72+
- The `render_view` decorator was forked from `render_to` in https://github.com/skorokithakis/django-annoying.
73+
- The `file`, `favicon_file` and `favicon_emoji` code is from https://adamj.eu/tech/2022/01/18/how-to-add-a-favicon-to-your-django-site/.

docs/source/index.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,51 @@
22

33
`django-fbv` includes utilities to make function-based views cleaner, more efficient, and better tasting. 💥
44

5-
## Why?
5+
## Why? 🤔
66

7-
The Django community has two ways to build views: class-based and function-based. This library is intended to solve for some of the annoyances of function-based views.
7+
The Django community has two ways to write views: [class-based](https://docs.djangoproject.com/en/stable/topics/class-based-views/) and [function-based](https://docs.djangoproject.com/en/stable/topics/http/views/). One benefit of function-based views is that the input of a `HttpRequest` and the `HttpResponse` output is explicit.
88

9-
If you want to read a more detailed critique of class-based views, https://spookylukey.github.io/django-views-the-right-way/ is excellent.
9+
`django-fbv` reduces the boilerplate code required when using function-based views. It also leverages _locality of behavior_ -- the name of the template is clearly associated to the view, instead of being part of the return statement.
1010

11-
## Installation
11+
Instead of this:
12+
13+
```python
14+
# sample_app/views.py
15+
from django.shortcuts import render
16+
17+
def regular_function_based_view(request):
18+
return render(request, "template_name.html", {"data": 123})
19+
```
20+
21+
You can write this:
22+
23+
```python
24+
# sample_app/views.py
25+
from fbv.decorators import render_html
26+
27+
@render_html("template_name.html")
28+
def django_fbv_view(request):
29+
return {"data": 123}
30+
```
31+
32+
```{note}
33+
If you want a more detailed critique of class-based views, I recommend reading [Django Views the Right Way](https://spookylukey.github.io/django-views-the-right-way/).
34+
```
35+
36+
## Installation ⚙️
1237

1338
`pip install django-fbv` OR `uv add django-fbv`
1439

15-
The [decorators](decorators.md) and [views](views.md) can be used by just importing them. The middleware [needs to be installed](middleware.md#installation).
40+
The [decorators](decorators.md) and [views](views.md) can be used by just importing them. The middleware [needs to be installed](https://django-fbv.adamghill.com/en/latest/middleware/#installation).
1641

17-
## Features
42+
## Features 🤩
1843

1944
### Decorators
2045

2146
- [`fbv.decorators.render_html`](https://django-fbv.adamghill.com/en/latest/decorators/#render-html): renders a view as HTML with the specified template
2247
- [`fbv.decorators.render_view`](https://django-fbv.adamghill.com/en/latest/decorators/#render-view): renders a view as a content type with the specified template
2348
- [`fbv.decorators.render_json`](https://django-fbv.adamghill.com/en/latest/decorators/#render-json):
24-
renders dictionaries, Django Models, or Django QuerySets as a JSON response
49+
renders dictionaries, Django `Model`, or Django `QuerySet` as a `JSON` response
2550

2651
### Views
2752

@@ -35,10 +60,11 @@ renders dictionaries, Django Models, or Django QuerySets as a JSON response
3560

3661
- [`fbv.middleware.RequestMethodMiddleware`](https://django-fbv.adamghill.com/en/latest/middleware/): adds a boolean property to the `request` for the current request's HTTP method
3762

38-
## Prior art
63+
## Prior art 🖼️
64+
65+
- The `render_view` decorator was forked from `render_to` in https://github.com/skorokithakis/django-annoying.
66+
- The `file`, `favicon_file` and `favicon_emoji` code is from https://adamj.eu/tech/2022/01/18/how-to-add-a-favicon-to-your-django-site/.
3967

40-
- The `render_view` decorator was forked from `render_to` in the delightful https://github.com/skorokithakis/django-annoying library.
41-
- The `file`, `favicon_file` and `favicon_emoji` code is from the superb https://adamj.eu/tech/2022/01/18/how-to-add-a-favicon-to-your-django-site/ blog post.
4268

4369
```{toctree}
4470
:maxdepth: 2

0 commit comments

Comments
 (0)