Comments (3)
No, it should not update the cache if your ForeignKey is changed. To quote the docs: "dbtemplates uses Django’s default caching infrastructure for caching, and operates automatically when creating, updating or deleting templates in the database". That applies to changing the templates, but not to setting relations to a template.
As to what you're trying to accomplish, I'm out of ideas. If you're simply changing the relation to a template, and use the template's name
field in your get_template_names
view method, I don't see how the cache needs to be invalidated at all. Each template has separate names after all, so the template loader will now what to do when it tries to load the template form the database.
from django-dbtemplates.
Good point about caching and ForeignKey relations. Maybe the issue is not related to caching? As you describe, I am returning the template's '' field in '<get_template_names>'. (I also have a default template as a fallback because the template field is not required).
So here's the sequence I just went though.
- No template set on model (ie foreignkey is empty) -> loads default template in browser, no problem
- Using admin, update template field on model, set to existing Template object in database ("foo/sometemplate.html"), save model. Still loads default template in browser (not sure why this is - I think this problem is in my code though).
- Restart server process
- Try to load page, error TemplateDoesNotExist (correctly returns the name of the Template object I chose "foo/sometemplate.html", however).
Debug Template-loader postmortem says:
Django tried loading these templates, in this order:
* Using loader dbtemplates.loader.Loader:
* Using loader django.template.loaders.filesystem.Loader:
* Using loader django.template.loaders.app_directories.Loader:
* places
* places
* etc
- Go to admin page, run "repopulate cache with selected templates"
- page loads with correct template from dbtemplates
from django-dbtemplates.
Further info:
Forgetting about the part with changing foreignkeys on my models...
If I leave the foreign key alone, and have no cache settings in my settings.py, I will get TemplateDoesNotExist when I try to load a page with that template. Then I go to the admin, "Repopulate cache with selected template", and the page loads ok. Wait a few minutes, and then try to load page again. I get TemplateDoesNotExist again.
So without cache settings created in settings.py, I'm not sure where the "Repopulate cache with selected template" is loading the template to. But it seems that the Loader is not correctly falling back to getting the template from the database if it fails to find it in the cache.
Hope that helps pinpoint the issue.
from django-dbtemplates.
Related Issues (20)
- ./manage.py sync_templates --help fails with TypeError
- Can not change the content at templates directory HOT 1
- CodeMirror Line Numbers are Offset in Admin Dashboard HOT 1
- Use with FileField HOT 1
- Translation Files Support HOT 1
- Drop the use for django.utils.six HOT 3
- package compatible with dj3.0
- Django 3.2 cache compatibility HOT 9
- Template name is not unique HOT 1
- Is this project deprecated? HOT 4
- Does not work with django 4
- New release on PyPi, maybe? HOT 6
- ChangeLog was not updated yet to version 4.0
- Jinja2
- migrations
- model translations
- Fatal Python error: _Py_CheckRecursiveCall HOT 1
- Static file loading not working when using S3 static storage (DBTEMPLATES_MEDIA_PREFIX)
- compatibility with django 4.2
- python3 compatibility: replace raw_input with input
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-dbtemplates.