[英]Python 2.7 and Flask - using functions from “Random” module returns “500 Internal Server Error” when using venv
我正在測試使用python和flask編寫的Web服務。 在該服務中,我想生成一個隨機數。 網絡上發布的所有解決方案似乎都無法正常工作, 好像“隨機”模塊無法正常工作。 我檢查了一下,在webservice.py周圍的文件夾中沒有random.py或random.pyc
這是我啟動Web服務的方式:
$ . venv/bin/activate
$ python webservice.py
在虛擬環境中運行時,如何解決隨機模塊不可用的問題?
import random
from random import randint
x = random.random()*100
x = randint(0,10)
print 'r' + x #does not work
這是venv文件夾中的內容:
檢查help(“ random”)方法是否會給出列表。
幫助鏈接。
好像您嘗試添加字符串和整數。
print 'x' + str(randint(0,10)) # try casting the int to string :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.