jeudi 28 décembre 2017

Python module random has no attribute choices working on local server but not on live server

I have a script which selects a random number form available list at random. I have been testing it on django's local server and it worked fine but when I moved it to a live server I keep getting this error:

AttributeError: 'module' object has no attribute 'choices'

Here's my code:

import json

class singlePull(TemplateView):
template_name = 'gacha/singlepull.html'

def randomStar(self):
    choice = [5,4,3]
    probability = [0.1, 0.2, 0.7]
    star = random.choices(choice, probability)
    return star


def post(self, request):
    result = self.randomStar()
    for key in result:
        character = Characters.objects.filter(stars=key).order_by('?')[:1]
        for obj in character:
            name = obj.name
            stars = obj.stars
            series = obj.series
            image = obj.image
    return JsonResponse({'name': name, 'stars': stars, 'series': series, 'image': image}, safe=False)

How come I keep getting this error? What could be wrong here?




Aucun commentaire:

Enregistrer un commentaire