Я попробовал все, но маршрут просто не работает. Я новичок в колбе, и я запускаю его на месте. Кроме того, мой угловой js-код дает 404 при отправке данных во флягу, поскольку маршрут, по-видимому, не существует.
app.py
@app.route('/')
@app.route('/index')
def IndexPage():
return render_template('index.html')
#these routes don't work although all of the others do which is very confusing
@app.route('/misc')
@app.route('/contact/mama')
def printHello():
return render_template('index.html')
@app.route('/contact')
def ContactPage():
return render_template('contact.html')
@app.route('/about')
def AboutPage():
return render_template('about.html')
if __name__ == '__main__':
app.run()
Вот мой угловой код и скрипт python, пытающийся обработать почтовый запрос
var formApp = angular.module('formController', []);
formApp.controller("formControl", function($scope,$http) {
alert("mama");
$scope.FormSubmit = function ()
{
alert("In the function");
var data =
{
name : $scope.user.name,
phone : $scope.user.phone,
email : $scope.user.email,
message : $scope.user.message
};
var result = $http.post('contact/userData', data, null);
result.success(function(response)
{
const message = response.status;
alert(message)
alert("Thanks for contacting us");
});
result.error(function(data, status, headers, config)
{
console.log(result)
alert("Error while submitting data");
});
$scope.user.name = '';
$scope.user.phone = '';
$scope.user.email = '';
$scope.user.message = '';
};
});
и вот скрипт python для обработки запроса
import sys
приложение для импорта
импорт JSON
из колбы запрос на импорт
@app.route("/contact/userData", methods=['GET','POST'])
def SendMail():
message = json.dump({'status': 'success'})
return message