KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am currently writing a few custom template tags but for some reason they will not load. My directory structure is as follows: MyProj | ----MyApp | |----templatetags | |----myapp_tags.py |----__init__.py In myapp_tags.py from django.template import Library, Node from myproj.myapp.models import Product register = Library() class LatestProductsNode(Node): def render(self, context): context['recent_products'] = Product.objects.all()[:5] return '' def get_latest_products(parser, token): return LatestProductsNode() get_latest_products = register.tag(get_latest_products) In settings.py INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'myproj.myapp', ) In the Template {% load myapp_tags %} The error i get when trying to load the page: Exception Type: TemplateSyntaxError Exception Value: 'myapp_tags' is not a valid tag library: Could not load template library from django.templatetags.myapp_tags, No module named myapp_tags
Tags (comma-separated)
Save Edits
Cancel