semvec/pypi-packages huggingface dataset:
demo-dont-use-danger-here 0.0.1
Foo and bar
Requires Python: >=3.9

# demo-dont-use-danger-here

[![PyPI](https://img.shields.io/pypi/v/demo-dont-use-danger-here.svg)][pypi status]
[![Status](https://img.shields.io/pypi/status/demo-dont-use-danger-here.svg)][pypi status]
[![Python Version](https://img.shields.io/pypi/pyversions/demo-dont-use-danger-here)][pypi status]
[![License](https://img.shields.io/pypi/l/demo-dont-use-danger-here)][license]

[![Read the documentation at https://demo-dont-use-danger-here.readthedocs.io/](https://img.shields.io/readthedocs/demo-dont-use-danger-here/latest.svg?label=Read%20the%20Docs)][read the docs]
[![Tests](https://github.com/brightway-lca/demo-dont-use-danger-here/actions/workflows/python-test.yml/badge.svg)][tests]
[![Codecov](https://codecov.io/gh/brightway-lca/demo-dont-use-danger-here/branch/main/graph/badge.svg)][codecov]

[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)][pre-commit]
[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)][black]

[pypi status]: https://pypi.org/project/demo-dont-use-danger-here/
[read the docs]: https://demo-dont-use-danger-here.readthedocs.io/
[tests]: https://github.com/brightway-lca/demo-dont-use-danger-here/actions?workflow=Tests
[codecov]: https://app.codecov.io/gh/brightway-lca/demo-dont-use-danger-here
[pre-commit]: https://github.com/pre-commit/pre-commit
[black]: https://github.com/psf/black

## Installation

You can install _demo_dont_use_danger_here_ via [pip] from [PyPI]:

```console
$ pip install demo_dont_use_danger_here
```

## Contributing

Contributions are very welcome.
To learn more, see the [Contributor Guide][Contributor Guide].

## License

Distributed under the terms of the [MIT license][License],
_demo_dont_use_danger_here_ is free and open source software.

## Issues

If you encounter any problems,
please [file an issue][Issue Tracker] along with a detailed description.


<!-- github-only -->

[command-line reference]: https://demo-dont-use-danger-here.readthedocs.io/en/latest/usage.html
[License]: https://github.com/brightway-lca/demo-dont-use-danger-here/blob/main/LICENSE
[Contributor Guide]: https://github.com/brightway-lca/demo-dont-use-danger-here/blob/main/CONTRIBUTING.md
[Issue Tracker]: https://github.com/brightway-lca/demo-dont-use-danger-here/issues


## Building the Documentation

You can build the documentation locally by installing the documentation Conda environment:

```bash
conda env create -f docs/environment.yml
```

activating the environment

```bash
conda activate sphinx_demo-dont-use-danger-here
```

and [running the build command](https://www.sphinx-doc.org/en/master/man/sphinx-build.html#sphinx-build):

```bash
sphinx-build docs _build/html --builder=singlehtml --jobs=auto --write-all; open _build/html/index.html
```
dj_component_view 9.0
Django component view for jinjax

# dj_component_view

This project lets you create reusable Django views from [jinjax](https://jinjax.scaletti.dev/) templates.

## Usage

### Greeting.jinja

```jinja
<h1>hello, {{ name }}</h1>
```

### views.py

```python
from djecorator import Route
from dj_component_view import component

route = Route()

@route("/components/greet")
@component("Greeting")
def greet(request):
    return {
        "name": request.GET.get("name", "World"),
    }
```


### index.html with [htmx](https://htmx.org)

```html
<form hx-get="{{ url('greet') }}" hx-trigger="submit">
  <input type="text" name="name" placeholder="Enter your name" />
  <button type="submit">Greet</button>
</form>
```

There is also a lower-level API which the `component` decorator uses under the hood.
The `ComponentView` class inherits from django's own `View` class.


```python
from dj_component_view import ComponentView
from djecorator import Route

route = Route()

@route("/greet", name="greet")
class GreetView(ComponentView):
    component = "Greeting"

    def render(self, request):
        return {
            "name": request.GET.get("name", "World"),
        }
```

### Specifying the Allowed HTTP Methods

You can set the `methods` class variable in your ComponentView subclass to specify the allowed HTTP methods for the view. The default value is `["GET"]`.

- If `methods` is set to `["GET"]`, only GET requests will be allowed.
- If `methods` is set to `["POST"]`, only POST requests will be allowed.
- If `methods` is set to `["GET", "POST"]`, both GET and POST requests will be allowed.

```python
@component("CustomComponent", methods=["post"])
def custom_component(request):
    ...

# or

class CustomView(ComponentView):
    component = "CustomComponent"
    methods = ["post"]

    ...

```

If the incoming request's method does not match any of the specified methods, a 405 Method Not Allowed response will be returned.

### Overriding the get and post Methods

If you need more control over the handling of GET and POST requests, you can override the get and post methods in your ComponentView subclass.

```python
@route("/custom")
class CustomView(ComponentView):
    component = "CustomComponent"
    methods = ["get"]

    def get(self, request, *args, **kwargs):
        # Custom implementation of the GET method
        ...
```