【发布时间】:2022-01-20 13:00:15
【问题描述】:
我已将我的 url 更改为 re_path,现在收到 404,未找到错误。有任何想法吗?这是我的 urls.py 和 html 代码,其中包括 ajax:
re_path(r'^get_mmm_ingredients/(?P<ingredient_type>\w+)/$', get_mmm_ingredients),
<script>
// populate ingredients
let ingredient;
$("select[name='ingredient_type']").change(function() {
const ingredient_type = $(this).val();
const data = {"item": ingredient_type};
ingredient = $("select[name='ingredient']");
$.ajax({
url: '/get_mmm_ingredients/' + ingredient_type + '/',
type: "GET",
data: data,
dataType: "json",
success: function(data) {
// empty value dropdown and add options
ingredient.empty();
ingredient.append('<option>Select</option>');
$.each(data, function (index, text) {
ingredient.append(
$('<option></option>').val(index).html(text)
);
});
}
});
});
</script>
【问题讨论】: