Python 如何在Django中的另一个应用程序的视图中使用my base.html模板?

Python 如何在Django中的另一个应用程序的视图中使用my base.html模板?,python,django,Python,Django,我正在尝试在我的页脚中实现一个时事通讯。我的页脚存储在我的base.html文件中,问题是我需要为另一个应用程序中的视图呈现此模板 这是我的密码: @csrf_exempt def new(request): if request.method == 'POST': sub = Subscriber(email=request.POST['email'], conf_num=random_digits()) sub.save() messa

我正在尝试在我的页脚中实现一个时事通讯。我的页脚存储在我的
base.html
文件中,问题是我需要为另一个应用程序中的视图呈现此模板

这是我的密码:

@csrf_exempt
def new(request):
    if request.method == 'POST':
        sub = Subscriber(email=request.POST['email'], conf_num=random_digits())
        sub.save()
        message = Mail(
            from_email=settings.FROM_EMAIL,
            to_emails=sub.email,
            subject='Newsletter Confirmation',
            html_content='Thank you for signing up for the StockBuckets email newsletter! \
                Please complete the process by \
                <a href="{}/confirm/?email={}&conf_num={}"> clicking here to \
                confirm your registration</a>.'.format(request.build_absolute_uri('/confirm/'),
                                                    sub.email,
                                                    sub.conf_num))
        sg = SendGridAPIClient(settings.SENDGRID_API_KEY)
        response = sg.send(message)
        return render(request, 'index.html', {'email': sub.email, 'action': 'added', 'form': SubscriberForm()})
    else:
        return render(request, 'index.html', {'form': SubscriberForm()})
@csrf\u豁免
def新(请求):
如果request.method==“POST”:
sub=Subscriber(email=request.POST['email'],conf_num=random_digits())
sub.save()
信息=邮件(
from_email=设置。from_email,
to_email=sub.email,
主题=‘时事通讯确认’,
html_content='感谢您注册StockBuckets电子邮件时事通讯\
请于\
.format(request.build_absolute_uri('/confirm/'),
sub.email,
sub.conf_num)
sg=SendGridApicClient(settings.SENDGRID\u API\u键)
响应=sg.send(消息)
返回呈现(请求'index.html',{'email':sub.email,'action':'added','form':SubscriberForm()})
其他:
返回呈现(请求'index.html',{'form':SubscriberForm()})

我想将此视图返回语句中的
index.html
实例替换为
base.html
。我该怎么做呢?

在Django中,所有模板文件都将收集在单个模板文件夹中。所以我们必须创造这样的东西

Django_project/
    app_1/
        ..
    app_2/
        ..
    app_3/
        ..
    Django_project/
        settings.py
        manage.py
    templates/
        app_1/
            base.html
            other.html
        app_2/
            base.html
            other.html
        app_3/
            base.html
            other.html
        other_common.html
或者用户可以在应用程序内部添加模板

Django_project/
    app_1/
        templates/
            app_1/
                base.html
                other.html
    app_2/
        templates/
            app_1/
                base.html
                other.html

现在,如果您想使用另一个应用程序的基本模板,请在渲染函数中添加“app_1/base.html”。

索引页和基本模板?还是只有基地?@navaneethkrishnan。非常确定我只需要在视图中呈现base.html模板