TypeError: missing 1 required positional argument (word counter app)

130 views
Skip to first unread message

drone4four

unread,
Jul 10, 2019, 1:13:16 PM7/10/19
to Django users

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.


drone4four

unread,
Jul 10, 2019, 1:13:33 PM7/10/19
to Django users

For what it is worth, here is some of the documentation I’ve been working with.


I’ve referred to official Django docs for:


Stack Overflow questions I’ve used:


Reply all
Reply to author
Forward
0 new messages