-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid block tag ... 'component'. Did you forget to register or load this tag? error #610
Comments
Hey @danjac, my guess is that this error relates to the TagFormatter feature, where the So my guess is that you didn't correctly register the Did you also configure |
I'm trying if at all possible to avoid using Is there a reason I can't just define them in the individual Python libraries e.g. under |
Please go over the documentation. See the section on Autodiscovery. We use It's possible not to use Like so in from django.apps import AppConfig
class MyAppConfig(AppConfig):
name = "my_app"
def ready(self) -> None:
from components.card.card import Card
from components.list.list import List
from components.menu.menu import Menu
from components.button.button import Button
... |
Just to clarify, .py and .html files are not included in the static assets when you use On a side note, I'm currently dealing with a somewhat related issue myself after updating from v0.28 (😱 a lot of progress you guys have made!), but I'll start a separate thread if I don't figure out a solution myself. |
@VojtechPetru Good point with Also, if, during the migration, there will be some non-obvious steps you will need to make, would you make a discussion and share them there? It could be helpful for others! |
I'm aware of the |
Hm, I agree it would be nice to get rid of Had a look and what would be required is probably to write a custom Finder for STATICFILES_FINDERS = [
# Default finders
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
# Django components
"django_components.finders.ComponentAssetsFinder",
] This means that we'd also need to define an additional setting for specifying where to look for components: COMPONENTS = {
"dirs": [
BASE_DIR / "templates",
],
} At this point, we could get rid of How it would work is that On the other hand, I have a lot on my plate already, so feel free to look into this. All interaction with |
Ok, I actually got some time, and got things working as described above :) There's couple of other tickets open, but I reckon we could get this merged in a week or two. |
Agree with @danjac's point that not being secure by default is a code smell. One obvious solution would be to move components out of static dirs altogether, and then somehow link into the collectstatic flow some other way... @JuroOravec About the solution you have above with specifying a component dir: I would expect this to work like with template dirs, that we would automatically look for "components" directories in all app dirs as well. |
@EmilStenstrom Yes, same logic and same input, users would just use One correction tho, we no longer automatically look into |
Was there a reason to remove the per-app autodiscover? As a Django developer this is the pattern I am used to (e.g. with Django admin discovery or app templates), along with a list of libraries in settings under Re JS/CSS lookup - we have the example in Django of |
@danjac re per-app-components, it wasn't documented, and it wasn't entirely clear how it should work, so I removed it for simplicity. To be specific, it didn't behave like top-level So IMO if we want to bring it back, I suggest it should work the same way as top-level components, that we search the directory contents automatically. As for You totally can keep JS/CSS with other static files and then just point component's JS/CSS to those. There's only a convenience sprinkled on top, which allows you to specify the JS/CSS location relative to the python file. |
Sure, but if you can live without that convenience, you can do away with needing to use
I would argue that autodiscover is a common Django idiom e.g. with top-level and per-app templates, template tags, Django admin, etc. Therefore having per-app discovery makes sense, with a way to specify module/package paths in settings (much like how template tag lookups work). Yes, it has to be documented, but it lets you lean on Django's existing mechanisms for autodiscovery and package lookup and would not be surprising to new users. |
@danjac I'd be interesting to hear / see what's your setup, and how you manage complexity. As for my experience, the project I work on it's probably mid-sized, it's currently around 70 components, 50 endpoints / views, and 20 pages. I use VSCode (haven't tried Pycharm or similar). Previously I kept components and views in totally different apps, but I just had to scroll so much, it was easy for me to lose focus. Now I keep the app-specific components within the relevant app, split components to For me personally it definitely lowers the mental overhead, and I'd rather have one more configuration step up front than cook my brains.
I'm making a note of that! |
Re In other words, make it an option, and enforce security checks if it is enabled. |
@danjac Hm, just to check I understand, are you talking about the case where python files are in STATICFILES_DIRS? So if we implemented this, where we'd configured component dirs via |
Yes, that's probably the better plan. |
@JuroOravec Thanks for correcting me regarding that we removed that strange, non-documented, behavior. I think the setup you describe is very sane: Per app-component dirs AND a global component dir for the global ones. I've seen many Django projects that has that setup for templates (app-specific + global). I wonder if we should make that the default for django_components as well? So if people put things in a components dir, things just work without any config. I think what I'm suggesting is making this the default:
|
This has now been released in v0.100 🎉 |
Great work, thank you!!! |
INSTALLED_APPS
TEMPLATES
as follows:Got the error "Invalid block tag on line 2: 'component'. Did you forget to register or load this tag?", indicating the template tag was not being loaded correctly
{% load component_tags %}
, same errorDjango 5.1,
django-components==0.92
The text was updated successfully, but these errors were encountered: