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

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

问题描述

好吧,这是一个很长的问题。我正在使用ExtJS和Django来创建一个网站。 Ive在互联网上搜索如何在获取IFrame时向url添加查询参数。所以bascily我有这个在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:'适合',
项目:[{
xtype:component,
autoEl:{
标签:iframe,
src:/ noVNC
}
}]
});

起初我以为我可以做

  src:/ noVNC?port = 5900

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

来自django.conf.urls.defaults import的$ $ code 

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

但我不知道如何使用view.py

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

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



谢谢

解决方案

我修改它很容易因为我的条件(我不需要我的任何参数在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:{
标签:iframe,
src:/ noVNC?con_port = 5901
}
}]
});

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

  src:/ noVNC?con_port = 590+ port 
/ pre>

views.py

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

urls.py

  urlpatterns = patterns('',
url(r'^ $','kfe 。
url(r'^ index $','kfe.views.index'),
url(r'^ noVNC $','kfe.views.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"
            }
    }]
});

At first I thought that I could just do

src: "/noVNC?port=5900"

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'),
)

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

Thanks

解决方案

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);

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天全站免登陆