Comments (11)
Thanks to hard work of @Real-Gecko (THANKS!) this is no released as part of 0.17.
from django-components.
Hi! What happens if you add the calendars directory to the DIRS setting? Does that solve the TemplateDoesNotExist error?
from django-components.
It did work with the following arrangement.
files:
tmp/components.py
tmp/components/calendar/static/calendar/script.js
tmp/components/calendar/static/calendar/style.css
tmp/components/calendar/templates/calendar.html
components.py
from django_components import component
@component.register("calendar")
class Calendar(component.Component):
def context(self, date):
return {
"date": date,
}
def template(self, context):
return "calendar/calendar.html"
class Media:
css = 'calendar/style.css'
js = 'calendar/script.js'
templates setting:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
str(APPS_DIR / 'templates'),
str(APPS_DIR / 'tmp' / 'components' / 'calendar' / 'templates')
], # APPS_DIR is ../mysite
stitic files dirs setting:
STATICFILES_DIRS = [
str(APPS_DIR / 'static'),
str(APPS_DIR / 'tmp' / 'components' / 'calendar' / 'static'),
]
I guess somebody needs to write a template loader and a static files finder for django to automatically find these files.
from django-components.
Thanks for posting the solution!
No matter what, you somehow need to specify the path to your templates. Are you suggesting we should come up with a default location for components, and make a loader that automatically loads templates from there?
from django-components.
Right, default locations like <app_name>/components/<component_name>/templates for templates and <app_name>/components/<component_name>/static for static files would be nice I think.
from django-components.
I've encountered the same issue. I'm trying to add component to app named common
. Here's how common/components.py
looks like:
from django_components import component
@component.register('permission_button')
class PermissionButton(component.Component):
def context(self, permission, url, caption):
return {
'permission': permission,
'url': url,
'caption': caption,
}
def template(self, context):
return 'common/components/permission_button/permission_button.html'
I get TemplateDoesNotExist
unless template itself is not in <BASE_DIR>/common/templates/common/components/permission_button/permission_button.html
from django-components.
@Real-Gecko Django only looks for templates in directories you have allowed in your TEMPLATES and STATICFILES_DIRS settings. So add your paths to your templates there.
from django-components.
Yep, but adding each component's template dir to settings.py
does not look that exciting, and keeping templates separately is against component
philosophy, I guess custom template loader for the app is the way to go.
from django-components.
@Real-Gecko Agreed. I'm opening this issue again, and changing the title to this. Would you mind making a PR?
from django-components.
Never done this before, will investigate Django documentation on custom template loaders.
from django-components.
It turned out to be pretty easy, check #85 for details.
from django-components.
Related Issues (20)
- Inner slot iteration malfunctioning HOT 11
- Middleware lets script placeholders slip through undeleted in certain cases HOT 2
- Using `if_filled` with the built in `if` HOT 11
- Become a jazzband project? HOT 4
- Components directory can't be found when multiple settings files are used HOT 3
- Not compatible with django-compressor HOT 20
- Problem with Selective Loading of JavaScript Files using `{% component_js_dependencies %}` Tag HOT 2
- ImportError: cannot import name 'Generic' from 'typing' HOT 4
- Seems I need to run "./manage collectstatic" to apply changes HOT 5
- I cant seem to get django-components working HOT 7
- Update README to use new management command
- Add test cases for `startcomponent` command
- ImportError due to Circular Import in auto-discover Process with django-unicorn HOT 3
- Automatic components from a template file HOT 7
- Latest release (0.30) doesn't match the code in master HOT 4
- Components as views HOT 11
- Use parent context in slots? HOT 17
- Add setting for specifying "only" keyword as the default HOT 1
- Pylance(reportIncompatibleVariableOverride): "Media" overrides symbol of same name in class "Component" HOT 3
- django_components.component_registry.AlreadyRegistered error when using component as view. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-components.