我的模板目录是否需要__init__.py文件?

时间:2019-05-01 19:28:52

标签: django python-3.x

我正在使用Django和Python 3.7。我的项目层次结构中有以下内容...

+ project
    + web
        + views
            tax_calculator.py
        + forms
            __init__.py
            tax_calculator_form.py
        + templates
            tax_calculator.html

我的视图文件“ tax_calculator.py”正尝试使用呈现GET请求

# Basic function that serves the default page
def get(request):
    tax_calculator_form = TaxCalculatorForm()
    return render(request, "web/templates/tax_calculator.html", {'form': tax_calculator_form})

但是我遇到了错误

TemplateDoesNotExist at /calculate_taxes

当我访问我的URL时,它在我看来抱怨此行

return render(request, "web/templates/tax_calculator.html", {'form': tax_calculator_form})

这条路对我来说似乎正确。为什么我的URL找不到我的模板路径?

1 个答案:

答案 0 :(得分:0)

为回答您的问题标题,编号<img data-src="@image" alt="" class="card-image lazy"> <noscript><img src="@image" alt="" class="card-image"></noscript> 用于python模块,而不用于资产目录

根据您指定template settings的方式,您不需要相对路径,__init__.py就足够了。