Ошибка в приложении Machine Learning Flask — jinja2.Exceptions.TemplateNotFound: index.htmlPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Ошибка в приложении Machine Learning Flask — jinja2.Exceptions.TemplateNotFound: index.html

Сообщение Anonymous »

Я выполняю проект Machine Learning Flask по прогнозированию цен на электромобили. Я застрял в проблеме в течение 2 дней.
После запуска команды python run.py я получаю эту ошибку на локальном хосте:

Код: Выделить всё

TemplateNotFound
jinja2.exceptions.TemplateNotFound: index.html

Traceback (most recent call last)
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\flask\app.py", line 1498, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\flask\app.py", line 1476, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\flask\app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()Open an interactive python shell in this frame
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\flask\app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\flask\app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\flask\app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
File "G:\Machine_Learning_Projects\2024\electric_vehicle_price_prediction_2\app\routes.py", line 7, in index
return render_template('index.html')
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\flask\templating.py", line 149, in render_template
template = app.jinja_env.get_or_select_template(template_name_or_list)
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\jinja2\environment.py", line 1084, in get_or_select_template
return self.get_template(template_name_or_list, parent, globals)
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\jinja2\environment.py", line 1013, in get_template
return self._load_template(name, globals)
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\jinja2\environment.py", line 972, in _load_template
template = self.loader.load(self, name, self.make_globals(globals))
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\jinja2\loaders.py", line 126, in load
source, filename, uptodate = self.get_source(environment, name)
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\flask\templating.py", line 65, in get_source
return self._get_source_fast(environment, template)
File "C:\Users\2021\.conda\envs\electric_vehicle_price_prediction_2\lib\site-packages\flask\templating.py", line 99, in _get_source_fast
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: index.html
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it.  For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
Вот мой код в файле Routes.py внутри папки приложения:

Код: Выделить всё

from flask import render_template, request, jsonify
from app import app
from app.model import predict_price

@app.route('/')
def index():
return render_template('index.html')

@app.route('/predict', methods=['POST'])
def predict():
data = request.form.to_dict()

# Convert the form data into the correct format for prediction
features = [
data['county'],
data['city'],
data['zip_code'],
data['model_year'],
data['make'],
data['model'],
data['ev_type'],
data['cafv_eligibility'],
data['legislative_district']
]

# Get the prediction result
price = predict_price(features)

return jsonify({'predicted_price': price}
)
Вот мой код в файле index.html внутри папки шаблона:

Код: Выделить всё





EV Price Prediction


Electric Vehicle Price Prediction


County:


City:


ZIP Code:


Model Year:


Make:


Model:


Electric Vehicle Type:


CAFV Eligibility:


Legislative District:





{% if predicted_price %}
Predicted Price: ${{ predicted_price }}
{% endif %}



Вот мой репозиторий на GitHub:
https://github.com/MdEhsanulHaqueKanan/ ... ediction-2
Глядя на другие подобные вопросы в Интернете, я подумал, что у меня может быть проблема со структурой папок моего проекта. Но я дважды проверил структуру папок. Я не обнаружил никаких проблем.
Вы можете увидеть структуру папок моего проекта здесь:

Код: Выделить всё

ev_price_prediction/
│
├── app/
│   ├── __init__.py
│   ├── routes.py
│   └── model.py
│
├── static/
│   └── style.css
│
├── templates/
│   └── index.html
│
├── dataset/
│   └── train.csv
│   └── test.csv
│
├── requirements.txt
└── run.py
Не могли бы вы помочь мне решить эту проблему?

Подробнее здесь: https://stackoverflow.com/questions/791 ... ound-index
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Ошибка в приложении Machine Learning Flask — jinja2.Exceptions.TemplateNotFound: index.html
    Anonymous » » в форуме Python
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous
  • Ошибка в приложении Machine Learning Flask — jinja2.Exceptions.TemplateNotFound: index.html
    Anonymous » » в форуме Python
    0 Ответы
    41 Просмотры
    Последнее сообщение Anonymous
  • Ошибка в приложении Machine Learning Flask — jinja2.Exceptions.TemplateNotFound: index.html
    Anonymous » » в форуме Python
    0 Ответы
    17 Просмотры
    Последнее сообщение Anonymous
  • TemplateNotFound jinja2.Exceptions.TemplateNotFound: index.html Traceback (последний вызов) [закрыто]
    Гость » » в форуме Python
    0 Ответы
    90 Просмотры
    Последнее сообщение Гость
  • Возникла проблема с jinja2.Exceptions.TemplateNotFound в моем приложении Python Flask.
    Anonymous » » в форуме Python
    0 Ответы
    21 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Python»