【问题标题】:Django - Changed url to re_path, now getting 404 errorDjango - 将 url 更改为 re_path,现在出现 404 错误
【发布时间】: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>

【问题讨论】:

    标签: jquery django ajax


    【解决方案1】:

    我通过将我的主要 urls.py 更改为:

    re_path(r'^', include('xxxxxxxxxx.urls')),
    

    【讨论】:

      猜你喜欢
      • 2013-08-11
      • 2013-09-22
      • 2021-09-17
      • 2011-07-06
      • 1970-01-01
      • 2018-10-01
      • 2017-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多