在Django模板中使用JavaScript重定向attemtp-产生无效的URL - javascript

我有一个非常简单的Django模板(尽管我是一个总有前端的菜鸟),我想在服务器IP地址更改后执行javascript重定向。

这实际上是服务器配置站点的一部分,该站点允许更改其IP(例如在路由器管理Web控制台上)。

Page向用户显示有关服务器将重新启动的信息,同时服务器将异步初始化重新启动顺序。一段时间延迟后,一个普通的javascript oneliner尝试在新IP地址上重新连接服务器。

在此示例中,我尝试将IP从:192.168.1.31更改为:192.168.1.41,但在显示信息页面之后:

# Server is now rebooting. If page doesn't open within 30 seconds, please refresh it with F5 button.
# Redirecting to: 192.168.1.41:8080/config

...我要进入以下错误页面:

# Page not found (404) Request Method:  GET Request URL:       
# http://192.168.1.31:8080/config/192.168.1.41:8080/config
# 
# Using the URLconf defined in cfgviewer.urls, Django tried these URL
# patterns, in this order:
# 
#     ^config/ ^$ [name='index']
#     ^admin/
# 
# The current URL, config/192.168.1.41:8080/config, didn't match any of
# these.
#
# You're seeing this error because you have DEBUG = True in your Django
# settings file. Change that to False, and Django will display a
# standard 404 page.

当IP地址更改并在POST请求中将redirect_address传递给它时,主页index.html重定向到reboot.html。

片段形式index.html:

(...)
context = {
(...)
   'redirect_address': redirect_address,
}

return render(request, 'cfgpanel/reboot.html', context)
(...)

Django reboot.html模板代码:

{% load staticfiles %}

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Server Configuration - rebooting...</title>
    </head>
<body>

<h1>Server is now rebooting. If page doesn't open within 30 seconds, please refresh it with F5 button.</h1>

{% if redirect_address != "" %}
<div>
    <h3 class="error_msg">Redirecting to: {{ redirect_address }}:8080/config</h3>
    <script type="text/javascript">

    window.setTimeout(function() {
        var new_url = "{{ redirect_address }}:8080/config";
        window.location.replace(new_url)
    }, 30000);

    </script>
</div>
{% endif %}

</body>
</html>

Django urls.py代码:

from django.conf.urls import url

from . import views

app_name = "config"
urlpatterns = [
    url(r'^$', views.index, name='index'),
]

问题:为什么客户端/浏览器没有尝试到达我要传递给它的绝对地址?如何使其打开192.168.1.41:8080/config而不是http://192.168.1.31:8080/config/192.168.1.41:8080/config?

参考方案

正如Kendas所建议的:

  在redirect_address前面加上“ http://”

做好了

剃刀付款集成->如何通过关闭按钮X检测剃刀付款模型是否关闭 - javascript

当用户关闭而无需付款时,我在CI框架中使用Razorpay,请创建razor支付模型,然后取消订单,我希望按状态更改为已取消的状态触发查询。所以我怎么能检测到这一点。我已经通过单击jQuery单击关闭功能但无法使用... javascript大神给出的解决方案 Razorpay提供了JS方法来检测模式关闭。您编写的任何JS代码都不会在结帐页面上运行,因为它是…

用多个通配符替换正则表达式可在PHP中工作,而不能在JavaScript中工作 - javascript

我正在尝试为两个Markdown解析器实现中心对齐:在Parsedown的PHP中(成功)在Bootstrap Markdown的JavaScript中(未成功)我遵循并找到最简单的方法是使用最终的HTML输出,只需将内联样式捕捉到标签上即可。以下正则表达式可以满足我的需要,它会根据需要将style="text-align:center;"…

JavaScript将PHP中的字符串和整数传递给函数 - javascript

我正在尝试将字符串和整数都传递到同一函数中,但是引号引起了问题。我发现错误出在echo $q->info部分,我必须在此代码上使用双引号。有人可以帮我写这个$q->info,但不能获得真正的价值吗?到目前为止,我的代码是<td><a href="javascript:add(<?php echo $q->i…

在提交时在表单操作中获取变量丢失 - javascript

            当表单由onchange事件提交时,它不会保留get变量view。任何想法为什么会发生这种情况?提交后,这是它进入的网址,index?month=February&year=2014<form action="index?view=list" class="pure-form pure-fo…

单击事件上的jQuery对于简单操作不起作用 - javascript

我正在做一个简单的jquery点击操作,它不起作用,我不知道它为什么发生的原因。我在控制台中看到输出(我也尝试过警报)这是我的代码:<script src="../jquery.min.js"></script> <script> $("#one").click(function()…