0👍
After thinkig about this question I came to conclusion that the best option is the one with middleware.
class CustomWordsMiddleware(object):
def process_response(self, request, response):
if request.user.settings == 'lumberjack':
response.content = response.content.replace("object", "tree")
response.content = response.content.replace("objects", "trees")
return response
Of course it is just example, I will also implement regexp instead of string replace. Moreover, I will use beautyful soup for parsing html to find classes where I should replace strings.
1👍
Disclaimer: I think something wrong with your project if you have to do this. Did you consider using variables?
Under Linux, this command will replace “orange” to “whale” in all files under current directory
find -type f -exec sed -i s/orange/whale/ {} \;
- [Answer]-Adding start separate page in django app
- [Answer]-How to install Django through subversion in Windows 7?
- [Answer]-Accessing bottle app using mod_wsgi
- [Answer]-Django update field
0👍
I can think of 2 scenarios base your question
- A user can replace any string in the templates. (Here I am assuming strings can only be replaced in templates)
- Or you have predefined collection of strings which user can change or overwrite.
If your problem matches scenario 1 then it is very difficult to implement any simple and clean solution to solve your problem. May be you can give users an HTML editor to rewrite the contents of template.
But if your problem matches scenario 2 then you can put all these pre-defined keywords in any persistent storage in the form of key:value pairs and when a user logged in then load these key:value pairs for that user in memory. And make your templates get the values of predefined keys from the memory (may be through Django contextprocessor).
- [Answer]-Django default settings 1.6 BASE_DIR acting up
- [Answer]-How will I get the time taken by a django orm query?
- [Answer]-Compare fields of same model
- [Answer]-Server Error (500) in accessing a section in Django app
0👍
This is more like an project architecture problem.
The best way of doing what i “think” you want is to:
- create a list of the “strings” options in a database.
- In the user model create a field like “chosen_string”
- When the user selects the option to be used (the string) you just update the user model
- whenever you want to use the strings , just do a query.
- [Answer]-Django field lookup returns case-insensitive result even with __exact
- [Answer]-How do I let Heroku Know I have a requirements.txt file
- [Answer]-CSRF protection on Django FormView