I’ve got a Python script which counts and prints the number of words in a 
text file. The script runs beautifully. It takes a public domain book (a 
text file such as Alice and Wonderland) which then counts the top 10 most 
used words (but which also filters out stopwords).  See here for some of my 
previous work: 
https://stackoverflow.com/questions/56436291/filtering-stop-words-out-of-a-large-text-file-using-package-nltk-corpus


Now I am trying to ‘port’ this Python shell script to Django. My intention 
for this project is to have the Django app count the number of words in a 
blog post. But for now I’m still using Alice and Wonderland in .txt format.


I’ve encountered some issues with my local dev server running but serving 
me a series of name errors involving my views module when I navigate to the 
url. I was hoping some of you could provide some insight.


When I run the server and navigate to http://127.0.0.1:8000/seth/, this is 
the error showing in my web browser pointing to the issue at hand: 
https://pastebin.com/52x2c4iN


Here is the traceback from my local Django dev server in my shell: 
https://pastebin.com/a8PTcRki


The file with the most problems is my counters/views.py (current app only): 
https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/views.py


I realize that the problem is with the way the text variable is tossed 
around. I probably should not be invoking global variables as I do at lines 
24, 38, 39 in my views model (above). Furthermore, out of the Udemy course 
material I’ve watched and in the official Django docs I’ve read, I’ve never 
seen a views.py which uses main() for calling functions. I realize I am 
sort of departing from Django norms here. What might you people recommend I 
try instead?


Here is counters/models.py:

https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/models.py


counters/forms.py: 
https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/forms.py 


urls.py in parent project directory: 
https://github.com/Angeles4four/CC_Redact_Iter2/blob/master/CC_Redact_Iter2/urls.py


Here is Alice and Wonderland in .txt format: 
https://github.com/Angeles4four/CC_Redact_Iter2/blob/v1.2/counters/Alice.txt


What other comments might you have about my code, in particular the 
views.py linked to above?


I’m running Django 2.2 and Python 3.7 on Manjaro.


Pull requests on GitHub are welcome although I realize if asking for pull 
requests like this might not be reasonable for most of you but I thought 
I’d say as always, just in case a kind and generous forum contributor has 
time on their hands. Requirements.txt is included on the master branch.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d9665256-b0e7-46fc-8b32-0cca19265acc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to