4

好的,所以这是一个很长的问题。我正在使用 ExtJS 和 Django 创建一个网站。我在互联网上搜索了如何在获取 IFrame 时向 url 添加查询参数。所以基本上我有这个,它在 ExtJS 中创建一个面板,其中有一个 html 页面。我希望能够在 url 中传递一个端口号,这样当它调用 html 时,它将自动拥有要与 vnc 连接的端口号。我的 VNC 客户端是 noVNC

var noVNC = Ext.create('Ext.panel.Panel', {
    title: "noVNC",
    frame: false,
    title: false,
    width: '100%',
    height: '100%',
    layout: 'fit',
    items: [{
        xtype: "component",
            autoEl: {
                tag: "iframe",
                src: "/noVNC"
            }
    }]
});

起初我以为我可以做到

src: "/noVNC?port=5900"

但是,(通过研究)我意识到你必须编辑 views.py 和 urls.py 我认为我的 urls.py 是正确的

from django.conf.urls.defaults import *

urlpatterns = patterns('',
     url(r'^$', 'kfe.views.index'),
     url(r'^index$', 'kfe.views.index'),
     url(r'^noVNC/(?P<port>\d+)/$' , 'kfe.views.noVNC'),
)

但我不确定如何使用views.py

def noVNC(request):
     return render(request, 'noVNC_Auto.html', content_type='text/html')

希望这是足够的信息。如果不告诉我

谢谢

4

1 回答 1

2

好的,由于我的条件,我修复它的方式非常容易(我不需要在 views.py 中的任何论点)。
所以我所做的是在我的 IFrame html 页面中我做了这个

window.onload = function () {
        con_port = "?port=" + WebUtil.getQueryVar('con_port', null);

在 ExtJS 里面我做了这个

var noVNC = Ext.create('Ext.panel.Panel', {
    title: "noVNC",
    frame: false,
    title: false,
    width: '100%',
    height: '100%',
    layout: 'fit',
    items: [{
        xtype: "component",
            autoEl: {
                tag: "iframe",
                src: "/noVNC?con_port=5901"
            }
    }]
});

现在我只是在端口号中硬编码,但你可以像这样将你的端口号添加到字符串中

src: "/noVNC?con_port=590" + port

视图.py

def noVNC(request):
    return render(request, 'noVNC_Auto.html', content_type='text/html')

网址.py

urlpatterns = patterns('',
    url(r'^$', 'kfe.views.index'),
    url(r'^index$', 'kfe.views.index'),
    url(r'^noVNC$' , 'kfe.views.noVNC'),
于 2011-07-13T15:52:10.140 回答