Django reads the txt file in view

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: