mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 06:18:17 +00:00
docs: Move docs-folder to root (#816)
* Move docs-folder form src to root * Avoid mkdocs package / module name clash * Update location of docs & add Windows compatibility * Update requirements-docs * Update generated file to current state
This commit is contained in:
parent
cdc830fca3
commit
594c0689ba
68 changed files with 116 additions and 108 deletions
26
docs/guides/setup/dev_server_setup.md
Normal file
26
docs/guides/setup/dev_server_setup.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
title: Running with development server
|
||||
weight: 2
|
||||
---
|
||||
|
||||
### Reload dev server on component file changes
|
||||
|
||||
This is relevant if you are using the project structure as shown in our examples, where
|
||||
HTML, JS, CSS and Python are in separate files and nested in a directory.
|
||||
|
||||
In this case you may notice that when you are running a development server,
|
||||
the server sometimes does not reload when you change component files.
|
||||
|
||||
From relevant [StackOverflow thread](https://stackoverflow.com/a/76722393/9788634):
|
||||
|
||||
> TL;DR is that the server won't reload if it thinks the changed file is in a templates directory,
|
||||
> or in a nested sub directory of a templates directory. This is by design.
|
||||
|
||||
To make the dev server reload on all component files, set
|
||||
[`reload_on_file_change`](#reload_on_file_change---reload-dev-server-on-component-file-changes)
|
||||
to `True`.
|
||||
This configures Django to watch for component files too.
|
||||
|
||||
!!! note
|
||||
|
||||
This setting should be enabled only for the dev environment!
|
34
docs/guides/setup/logging_and_debugging.md
Normal file
34
docs/guides/setup/logging_and_debugging.md
Normal file
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
weight: 3
|
||||
---
|
||||
|
||||
Django components supports [logging with Django](https://docs.djangoproject.com/en/5.0/howto/logging/#logging-how-to).
|
||||
This can help with troubleshooting.
|
||||
|
||||
To configure logging for Django components, set the `django_components` logger in
|
||||
[`LOGGING`](https://docs.djangoproject.com/en/5.1/ref/settings/#std-setting-LOGGING)
|
||||
in `settings.py` (below).
|
||||
|
||||
Also see the [`settings.py` file in sampleproject](https://github.com/EmilStenstrom/django-components/blob/master/sampleproject/sampleproject/settings.py) for a real-life example.
|
||||
|
||||
```py
|
||||
import logging
|
||||
import sys
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
"handlers": {
|
||||
"console": {
|
||||
'class': 'logging.StreamHandler',
|
||||
'stream': sys.stdout,
|
||||
},
|
||||
},
|
||||
"loggers": {
|
||||
"django_components": {
|
||||
"level": logging.DEBUG,
|
||||
"handlers": ["console"],
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
45
docs/guides/setup/syntax_highlight.md
Normal file
45
docs/guides/setup/syntax_highlight.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
title: Syntax highlighting
|
||||
---
|
||||
|
||||
## VSCode
|
||||
|
||||
Note, in the above example, that the `t.django_html`, `t.css`, and `t.js` types are used to specify the type of the template, CSS, and JS files, respectively. This is not necessary, but if you're using VSCode with the [Python Inline Source Syntax Highlighting](https://marketplace.visualstudio.com/items?itemName=samwillis.python-inline-source) extension, it will give you syntax highlighting for the template, CSS, and JS.
|
||||
|
||||
## Pycharm (or other Jetbrains IDEs)
|
||||
|
||||
If you're a Pycharm user (or any other editor from Jetbrains), you can have coding assistance as well:
|
||||
|
||||
```python
|
||||
from django_components import Component, register
|
||||
|
||||
@register("calendar")
|
||||
class Calendar(Component):
|
||||
def get_context_data(self, date):
|
||||
return {
|
||||
"date": date,
|
||||
}
|
||||
|
||||
# language=HTML
|
||||
template= """
|
||||
<div class="calendar-component">Today's date is <span>{{ date }}</span></div>
|
||||
"""
|
||||
|
||||
# language=CSS
|
||||
css = """
|
||||
.calendar-component { width: 200px; background: pink; }
|
||||
.calendar-component span { font-weight: bold; }
|
||||
"""
|
||||
|
||||
# language=JS
|
||||
js = """
|
||||
(function(){
|
||||
if (document.querySelector(".calendar-component")) {
|
||||
document.querySelector(".calendar-component").onclick = function(){ alert("Clicked calendar!"); };
|
||||
}
|
||||
})()
|
||||
"""
|
||||
```
|
||||
|
||||
You don't need to use `types.django_html`, `types.css`, `types.js` since Pycharm uses [language injections](https://www.jetbrains.com/help/pycharm/using-language-injections.html).
|
||||
You only need to write the comments `# language=<lang>` above the variables.
|
Loading…
Add table
Add a link
Reference in a new issue