Previous Lesson: Lesson 11: Display the User’s Text Using Django

Finally, we’re now gonna count the user’s text using Django! Of course, we’ll need to do something in our code to accomplish that.

On views.py:

Do this:

We’ve just pressed ENTER between the ‘count.html’ and the {‘fulltext’:full_text}). Why did we do this? Later, we will be adding something that will make this line very long, so doing this is necessary. Now, do this on your views.py:

We removed the print on Line 9, and then we added some things. And that includes this full_text.split(). From the word itself, this method splits up sentences, and then converts it to a list. Then we assigned this action to the variable wordlist. You good? Good. Now let’s add things again:

We added another pair of key:value on Line 13. We have count as the key, and len as its value. If you checked out that reference that I gave you about the split() function, you’ll also see the len function on that Python lesson. But len just counts the length or the number of values (may it be the number of str, or int, or float, etc.

Now, let’s use our count key on our count.html:

Then, let’s go back to our count page, reload, and see if everything works:

Yes! It worked! Let’s have another set of text here, shall we? Let’s go back to our homepage:

Hit COUNT:

Let’s count a long text!

I think I wanna try entering a longer text now. Let’s check out what’s new (at least, what’s new for me by the time I published this post) on jw.org:

Alright, let’s Get the Answer (Or, in your case, choose any topic in this website that interests you.):

Command + C, or Ctrl + C (copy). And then I’ll paste it here:

Command + V, or Ctrl + V (paste):

Now, let’s COUNT:

Yay! We were able to count the user’s text using Django! And we now have a website that counts our text! You know, we can stop here and just count the number of text. That can be a bit boring you know.

But what if we could add some features like counting the frequency of occurrence of every word in the text? Isn’t that much more fun? For example, the word “Bible” here on my text counts 14.

Take a look at this website: wordcounter.net and get inspired! This is me trying this website:

This website is plain and beautiful. But, we’ll not strive having a website that’s as beautiful as this (because we are going to do that on our second website). I just showed you this so that you’ll get inspired of what we can do with Python and Django.

As you can see in that website, it had the Details that talks about the number of words, characters, sentences, paragraphs, and even a reading level, reading time, and a speaking time! We’ll not have that in this website. Instead, what we do want to have is that Keyword Density right down below it.

By the time you finish the next lesson, you’ll have that kind of Keyword Density. See you there!

Next Lesson: Lesson 13: Get the Keyword Density Using Django

Leave a Reply

Your email address will not be published. Required fields are marked *