diff --git a/README.md b/README.md index 5b9e3c28..9c36bd88 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ Read on to learn about the details! # Release notes +*Version 0.22* starts autoimporting all files inside components subdirectores, to simplify setup. An existing project might start to get AlreadyRegistered-errors because of this. To solve this, either remove your custom loading of components, or set "autodiscovery": False in settings.COMPONENTS. + *Version 0.17* renames `Component.context` and `Component.template` to `get_context_data` and `get_template_name`. The old methods still work, but emit a deprecation warning. This change was done to sync naming with Django's class based views, and make using django-components more familiar to Django users. `Component.context` and `Component.template` will be removed when version 1.0 is released. # Installation @@ -28,19 +30,19 @@ Install the app into your environment: > ```pip install django_components``` -Then add the app into INSTALLED APPS in settings.py +Then add the app into INSTALLED_APPS in settings.py ```python INSTALLED_APPS = [ ..., "django_components", - ... ] ``` Modify `TEMPLATES` section of settings.py as follows: -- Remove `'APP_DIRS': True,` +- *Remove `'APP_DIRS': True,`* - add `loaders` to `OPTIONS` list and set it to following value: + ```python TEMPLATES = [ { @@ -60,6 +62,16 @@ TEMPLATES = [ }, ] ``` + +Modify STATICFILES_DIRS (or add it if you don't have it) so django can find your static JS and CSS files: + +```python +STATICFILES_DIRS = [ + ..., + BASE_DIR / "components", +] +``` + ## Optional To avoid loading the app in each template using ``` {% load django_components %} ```, you can add the tag as a 'builtin' in settings.py @@ -80,6 +92,8 @@ TEMPLATES = [ ] ``` +Read on to find out how to build your first component! + # Contributors @@ -192,7 +206,7 @@ A component in django-components is the combination of four things: CSS, Javascr First you need a CSS file. Be sure to prefix all rules with a unique class so they don't clash with other rules. ```css -/* In a file called [your app]/components/calendar/style.css */ +/* In a file called [project root]/components/calendar/style.css */ .calendar-component { width: 200px; background: pink; } .calendar-component span { font-weight: bold; } ``` @@ -200,30 +214,31 @@ First you need a CSS file. Be sure to prefix all rules with a unique class so th Then you need a javascript file that specifies how you interact with this component. You are free to use any javascript framework you want. A good way to make sure this component doesn't clash with other components is to define all code inside an anonymous function that calls itself. This makes all variables defined only be defined inside this component and not affect other components. ```js -/* In a file called [your app]/components/calendar/script.js */ +/* In a file called [project root]/components/calendar/script.js */ (function(){ - $(".calendar-component").click(function(){ alert("Clicked calendar!"); }) + document.querySelector(".calendar-component").onclick = function(){ alert("Clicked calendar!") } })() ``` Now you need a Django template for your component. Feel free to define more variables like `date` in this example. When creating an instance of this component we will send in the values for these variables. The template will be rendered with whatever template backend you've specified in your Django settings file. ```htmldjango -{# In a file called [your app]/components/calendar/calendar.html #} +{# In a file called [project root]/components/calendar/calendar.html #}