ExtJs 转 DJango url 查询参数 [英] ExtJs to DJango url query parameters

查看:25
本文介绍了ExtJs 转 DJango url 查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Ok So this is kinda a long question. I am using ExtJS and Django to create a websiteish. Ive search the internet on how to add query parameters to the url when get an IFrame. So bascily I have this which creates a panel in ExtJS which has an html page with in it. I want to be able to pass a port number with in the url so that when it calls the html it will automaticly have the port number to connect to with vnc. My VNC client is 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 是正确的

However, (through research) I realized you have to edit views.py and urls.py I think i have urls.py correct

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

But I am not sure how to use the views.py

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

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

hope that is enough info. If not just tell me

谢谢

推荐答案

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

Ok so the way I fixed it was very easily because of my conditions (I did not need any of my arguments in views.py).
So what I did was inside my IFrame html page I did this

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

在 ExtJS 中我做了这个

and inside ExtJS I did this

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"
            }
    }]
});

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

for now I just hard coded in the port number but you can just add your port number to the string like so

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

views.py

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

urls.py

urlpatterns = patterns('',
    url(r'^$', 'kfe.views.index'),
    url(r'^index$', 'kfe.views.index'),
    url(r'^noVNC$' , 'kfe.views.noVNC'),

这篇关于ExtJs 转 DJango url 查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆