我有一个控制器,其API只能在本地网络上访问,本地地址为10.0.1.7。当我在本地网络(http://127.0.0.1:8000/)上托管Django时,我能够成功发布到控制器API。但是,当我从外部托管网站(我们称之为www.djangolan.com)时,该帖子不会执行。我想知道是否有配置设置/权限的方法,以便当从站点www.djangolan.com发布帖子,同时将我的设备连接到LAN时,它可以执行。有没有办法使用Django python从托管网站发布到本地IP地址?
def user_created(request):
contents = {}
if request.method == 'POST':
form = PostForm(request.POST)
if form.is_valid():
firstName = form.cleaned_data['firstName']
lastName = form.cleaned_data['lastName']
url = "http://adminname:[email protected]/api/"
fullName = lastName + " , " + firstName
createUserJSON = {"SetUser":
{"User": [{
"Name": fullName,
"Description": "",
"Attribute": [
{
"type": "",
"Name": "FirstName",
"Value": firstName
},
{
"type": "",
"Name": "LastName",
"Value": lastName
}
]
}]
}
}
r = requests.post(url,json=createUserJSON)
return render(request,'user_created.html',contents)