Problem description:
In view, you want to load a TXT of block-words to block out dirty words.
but cannot find the file
Solutions:
Use the full path, put TXT under the same path as view.py, and add the first two lines
module_dir = os.path.dirname(__file__)
file_path = os.path.join(module_dir, 'block-words.txt') # full path to text.
block_words = pd.read_csv(file_path,header=None)
Subsequent operation:
Use find to match, replacing all matched words with asterisks
for word inblock_words[0]:
if info.find(word) != -1:
info = info.replace(word, '*' * len(word))
Read More:
- python reads csv file is an error _csv.Error: iterator should return strings, not bytes (did you open the file in text)
- Python reads the configuration file. Ini and resolves the error
- How to solve the problem of error reporting in the introduction of Python Django no module name ‘Django. Utils. Six’
- When Python Django creates a database, can’t open file ‘ manage.py ‘: [Errno 2] No such file or directory
- Linux use ls to view the file color is all white solution, and Linux file color introduction
- django.db.utils.OperationalError: no such table: django_admin_log
- django.core.exceptions . improveconfigured: error loading MySQL DB module. Django configuring MySQL database
- Some mistakes and solutions in Django
- This function has none of deterministic, no SQL, or reads SQL data in its error records
- R reads JSON data
- How to Disable Protected View in Microsoft Excel
- Four ways to get Django parameters in request
- Error in header file when calling OpenGL to open obj file in vs2013: unable to open include file: “GL / glut. H”: no such file or directories
- How to generate and view SSH keys in Ubuntu 16.04
- Solutions to Django is not importable in this environment
- Express error: Failed to lookup view “error” in views directory processing
- express nodejs Failed to lookup view error in views directory (How to Fix)
- Error generating Ca in OpenSSL: TXT_ DB error number 2
- Running Django (2.2) project in Python 3.7.9 reports an error