ExtJs to DJango url query parameters

♀尐吖头ヾ 提交于 2019-12-06 04:23:36

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/6672551/extjs-to-django-url-query-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!