mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 15:39:08 +00:00
Improve structure of sampleproject.
This commit is contained in:
parent
18ee5ad3b0
commit
c0ed45b920
7 changed files with 14 additions and 8 deletions
|
@ -4,6 +4,3 @@ from django.apps import AppConfig
|
||||||
class CalendarappConfig(AppConfig):
|
class CalendarappConfig(AppConfig):
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = "calendarapp"
|
name = "calendarapp"
|
||||||
|
|
||||||
def ready(self):
|
|
||||||
from components.calendar import calendar # NOQA
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
.calendar-component { width: 200px; background: pink; }
|
||||||
|
.calendar-component span { font-weight: bold; }
|
|
@ -1 +1 @@
|
||||||
Today's date is <span>{{ date }}</span>
|
<div class="calendar-component">Today's date is <span>{{ date }}</span></div>
|
|
@ -0,0 +1,3 @@
|
||||||
|
(function(){
|
||||||
|
document.querySelector(".calendar-component").onclick = function(){alert("Clicked calendar!")}
|
||||||
|
})()
|
|
@ -3,8 +3,9 @@ from django_components import component
|
||||||
|
|
||||||
@component.register("calendar")
|
@component.register("calendar")
|
||||||
class Calendar(component.Component):
|
class Calendar(component.Component):
|
||||||
# Note that Django will look for templates inside `[your app]/components` dir
|
# Note that Django will look for templates inside `[your apps]/components` dir and
|
||||||
# To customize which template to use based on context override get_template_name instead
|
# `[project root]/components` dir. To customize which template to use based on context
|
||||||
|
# you can override def get_template_name() instead of specifying the below variable.
|
||||||
template_name = "calendar/calendar.html"
|
template_name = "calendar/calendar.html"
|
||||||
|
|
||||||
# This component takes one parameter, a date string to show in the template
|
# This component takes one parameter, a date string to show in the template
|
||||||
|
@ -14,5 +15,5 @@ class Calendar(component.Component):
|
||||||
}
|
}
|
||||||
|
|
||||||
class Media:
|
class Media:
|
||||||
css = "calendarapp/components/calendar/calendar.css"
|
css = "calendar/calendar.css"
|
||||||
js = "calendarapp/components/calendar/calendar.js"
|
js = "calendar/calendar.js"
|
||||||
|
|
|
@ -122,6 +122,9 @@ USE_TZ = True
|
||||||
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = "static/"
|
STATIC_URL = "static/"
|
||||||
|
STATICFILES_DIRS = [
|
||||||
|
BASE_DIR / "components",
|
||||||
|
]
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue