问题是连接到 django 时显示框架集

问题描述 投票:0回答:2

有代码#index.html

    <html>
    <head>
        <title></title>
    </head>
    <frameset rows=100% >
        <frameset rows=76%,24% >
            <frameset cols=64%,36% >
                <frame name=reports src="reports.html" >
                <frame name=fg_log src=/****.py >
            </frameset>
            <frameset cols=64%,36% >
                <frame name=fp_log src=/********.py?fp=3&files=on >
                <frame name=ls src=/*******.py >
            </frameset>
        </frameset>
    </frameset>
</html>

启动时,只需通过浏览器打开 index.html - 我看到第一帧的数据

但是如果你开始通过 django 显示相同的 index.html - 我看到 404 而不是 hello world

我还在终端中看到一个错误

我还没有找到为什么会这样以及如何解决的答案,但我需要使用框架集

urls.py
from django.urls import path, include

from . import views

app_name = 'core'

urlpatterns = [
    path('', views.index, name='index'),

]

views.py

User = get_user_model()
@login_required
def index(request):
    template = 'core/index.html'
    return render(request, template)

template index.html 我附在上面。 启动django没有问题

添加新评论 问题还没解决

urls.py
from django.urls import path, include
from . import views

app_name = 'core'

urlpatterns = [
    path('', views.index, name='index'),
    path('reports', views.reports, name='reports-name'),
]

views.py
@login_required
def index(request):
    template = 'core/index.html'
    return render(request, template)


def reports(request):
    template = 'core/reports.html'
    return render(request, template)

index.html

<html>
    <head>
        <title></title>
    </head>
    <frameset rows=100% >
        <frameset rows=76%,24% >
            <frameset cols=64%,36% >
                <frame name=reports src="{% url 'core:reports-name' %}">
                <frame name=fg_log src=/cgi-bin/sendjobs.py >
            </frameset>
            <frameset cols=64%,36% >
                <frame name=fp_log src=/cgi-bin/fp_log.py?fp=3&files=on >
                <frame name=ls src=/cgi-bin/ls.py >
            </frameset>
        </frameset>
    </frameset>
</html>

reports.html

hello world

python html django frameset
2个回答
0
投票

有2个场景:

  1. reports.html 是一个动态模板文件,由 django 应用程序/视图通过 url 呈现和提供服务
  2. reports.html 只是一个要从服务器下载的静态文件

添加 1) 如果您想像应用程序中的任何其他 URL 一样在框架中下载 reports.html,您需要在应用程序的 urls.py 中安装该路径,例如:

urls.py
from django.urls import path, include
from . import views

app_name = 'core'

urlpatterns = [
    path('', views.index, name='index'),
    path('reports', views.reports, name='reports-name'),
]

...创建视图:

def reports(request):
    template = 'core/reports.html'
    return render(request, template)

...并将 url 标记添加到 index.html:

(这是使用 urls.py 作为单点来定义 url 模式并在其他任何地方通过名称引用它们的 django 方式)

<frame name=reports src="{% url 'core:reports-name' %}">

使用上述路径,这将转化为:

<frame name=reports src="reports">

add 2) 然后它是一个静态文件,应该像 django 文档中描述的那样对待:https://docs.djangoproject.com/en/4.2/howto/static-files/


0
投票

非常感谢 向“Razenstein”寻求帮助,解决问题需要禁用:

"settings">"MIDDLEWARE">"# 'django.middleware.clickjacking.XFrameOptionsMiddleware',"
© www.soinside.com 2019 - 2024. All rights reserved.