I'm wondering what “best practice” is for storing medium-length strings to be used in the user interface in Python / Django.
Example: I have an error.html template that accepts the error_description field. These are a few suggestions that explain to the user what went wrong and what they can do to solve it. It may differ for different error pages, but it remains quite stable in the code (there is no reason why someone who cannot promote the source code should be able to modify it), and it can be easily kept in memory, so I can’t think that this is what you need to store in the database.
My current idea is that I should just create some kind of messages.py file that has a bunch of string constants like this:
ERROR_UNAUTHENTICATED_AJAX_EXPLANATION = "Hello, so the only way that this error should occur is if someone attempts to directly call our AJAX endpoint without having the verification code. Please don't do this, it against the principles of this art projects."
In general, is there any canonical way to store strings that are "too flexible for hard coding" but "too small and static for databases" (and not scaled when you use it)? I am thinking about what would be in the strings.xml file in an Android project.
Other features that I juggle include a text file that views.py reads and saves as constants, actually just encodes them and inserts them into template files.
There are many ways to do this, and this is not a very difficult thing, I just want to know which one is the most “correct” one.
Thanks! And let me know if you need more information!
source share