2👍
For user specific variables, use session.
For global constants (not variables!), use settings.py
.
For global variables, consider to store it in database so it can be multithreading & multiprocess safe.
0👍
I looked around and saw different approaches,but one that doesn’t compromise the DRY philosophy the most for me is registering a tag in your project then input it in the base template.Its neater See here https://stackoverflow.com/a/21062774/6629594 for an example
- How to pre-select dropdown on Django?
- Update list of objects with AJAX
- Setting a default value in session if key does not exist
- How to find the database a Django record was loaded from?
- 'ManyToManyField' queries
0👍
Storage can take any number of places, I put mine in a stats model in the db so you get all the goodness of that (and make it easy to access in views).
I then have a context processor written as so:
#context_processors.py:
def my_custom_context_processor(request):
return {'custom_context_variable1':'foo','custom_context_variable2':'bar'}
Add this to your context processors in settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
...
"my_app.context_processors.ny_custom_context_processor",
)
Provided you use render() to render your templates you can then you can just use:
{{ custom_context_variable1 }}
to return ‘foo’ in your template. Obviously returning strings is for example only, you can use anything you like so long as your context processor returns a dict.
- TypeError("Cannot convert %r to Decimal" % value) TypeError: Cannot convert <LenderInvestment: 20000.00> to Decimal
- Accessing models linked to a Django user
- Badly Formed hexadecimal uuid string error in Django fixture
-1👍
you can also try using php pages.
Then acces the variable on each page with an include ‘file containing the var.php’ on every page.
None of this will be visible in the source html as it is only processed on the server side.
If you you would like to try this, mail me and I will send you some sample code.
- Django rest_social_auth log in. What to do with facebook token?
- How i can get User id by student id?
- Pass User obj to view trough custom authentication