我的.joblib文件和www.example.com在同一个目录下views.py实际上是紧挨着的,但是views.py无法加载它,一旦我运行服务器,就会抛出FileNotFoundError。
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
import joblib
@csrf_exempt
def test(response):
if response.method == 'POST':
age = int(response.POST['age'])
gender_str = str(response.POST['gender'])
if gender_str == 'Male':
gender_value = 1
else:
gender_value = 0
openness = int(response.POST['openness'])
neuroticism = int(response.POST['neuroticism'])
conscientiousness = int(response.POST['conscientiousness'])
agreeableness = int(response.POST['agreeableness'])
extraversion = int(response.POST['extraversion'])
personality_values_1 = [[gender_value, age, openness, neuroticism, conscientiousness, agreeableness, extraversion]]
theModel = joblib.load('PersonalityTestLogisticRegression.joblib')
prediction = theModel.predict(personality_values_1)
prediction_value = prediction[0]
return render(response, "main/Review_Test.html", {'prediction':prediction_value})
我试了所有我能做的,我是新的django。拉我的头发。
1条答案
按热度按时间sq1bmfud1#
尝试使用相对导入。
变更为: