且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ExtJs到DJango url查询参数

更新时间:2023-02-23 17:38:50

我修改它很容易因为我的条件(我不需要我的任何参数在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'),