from random import choice

from django.conf import settings


words = open(settings.WORDS_PATH, "r").readlines()


def random_words(total):
    return " ".join([choice(words).lower().rstrip() for i in range(total)])


def random_paragraphs(total, word_no=30):
    return ".\n\n".join([random_words(word_no) for i in range(total)])

from random import choice

from django.conf import settings
from django.utils.encoding import smart_text


words = open(settings.WORDS_PATH, "r").readlines()


def random_words(total):
    return u" ".join([smart_text(choice(words).lower().rstrip()) for i in range(total)])


def random_paragraphs(total, word_no=30):
    return u".\n\n".join([random_words(word_no) for i in range(total)])

Handle encoding of the random words.
Handle encoding of the random words.

  from random import choice
  
  from django.conf import settings
+ from django.utils.encoding import smart_text
  
  
  words = open(settings.WORDS_PATH, "r").readlines()
  
  
  def random_words(total):
-     return " ".join([choice(words).lower().rstrip() for i in range(total)])
+     return u" ".join([smart_text(choice(words).lower().rstrip()) for i in range(total)])
  
  
  def random_paragraphs(total, word_no=30):
-     return ".\n\n".join([random_words(word_no) for i in range(total)])
+     return u".\n\n".join([random_words(word_no) for i in range(total)])
  
Handle encoding of the random words.
## Code Before:
from random import choice

from django.conf import settings


words = open(settings.WORDS_PATH, "r").readlines()


def random_words(total):
    return " ".join([choice(words).lower().rstrip() for i in range(total)])


def random_paragraphs(total, word_no=30):
    return ".\n\n".join([random_words(word_no) for i in range(total)])

## Instruction:
Handle encoding of the random words.
## Code After:
from random import choice

from django.conf import settings
from django.utils.encoding import smart_text


words = open(settings.WORDS_PATH, "r").readlines()


def random_words(total):
    return u" ".join([smart_text(choice(words).lower().rstrip()) for i in range(total)])


def random_paragraphs(total, word_no=30):
    return u".\n\n".join([random_words(word_no) for i in range(total)])
