我已经在具有nginx和uwsgi的服务器上部署了django Web应用程序。我可以使用ip地址完美访问该网站。
我购买了一个域名abc.example.com,并将其指向我的IP地址。现在,当我转到域名时,它将加载一个空白页面并在浏览器控制台中引发错误:
在Chrome中:
Refused to display 'ip address' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
Run Code Online (Sandbox Code Playgroud)
在Mozilla中:
Load denied by X-Frame-Options: 'ip address' does not permit cross-origin framing.
Run Code Online (Sandbox Code Playgroud)
关键是我在整个应用程序中没有任何iframe。
这是什么错误,我该如何解决?
当我使用ip地址转到应用程序时,它可以像预期的那样完美运行。那么域的问题是什么?我仔细检查了Godaddy的dns区域中的设置,但什么都没找到。
我正在使用api从网站上获取订单.问题是,它一次只能获取20个订单.我想我需要使用分页迭代器,但不知道使用它.如何一次获取所有订单.
我的代码:
def search_orders(self):
headers = {'Authorization':'Bearer %s' % self.token,'Content-Type':'application/json',}
url = "https://api.flipkart.net/sellers/orders/search"
filter = {"filter": {"states": ["APPROVED","PACKED"],},}
return requests.post(url, data=json.dumps(filter), headers=headers)
Run Code Online (Sandbox Code Playgroud)
这是文档的链接.
我正在使用带有 python 的 PDFkit 将 html 页面转换为 pdf。在 html 中,body 中只有一个图像标签,其中 src 指向一个完整的 url,例如:
<html>
<body style="margin: 0px;">
<img style="-webkit-user-select: none; cursor: -webkit-zoom-in;" src="https://blah.blah.com" height="768">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是,当我像这样将 html 转换为 pdf 时:
pdfkit.from_file(file, 'labels.pdf', configuration=config)
Run Code Online (Sandbox Code Playgroud)
我得到一个带有边框而不是图像的框的空白页。
为什么pdfkit不转换图像?
我在某处读到我们必须提供包括域名在内的完整图像路径。但是我提供的图片网址是完整的。那我做错了什么?
我的代码:
import psycopg2
import requests
from urllib.request import urlopen
import urllib.parse
uname = " **** "
pwd = " ***** "
resp = requests.get("https://api.flipkart.net/sellers/skus/SKUID/listings", auth=(uname, pwd))
con_page = resp.content()
print (con_page)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Traceback (most recent call last):
File "C:\Users\Prime\Documents\NetBeansProjects\Fp_API\src\fp_api.py", line 18, in <module>
con_page = resp.content()
TypeError: 'bytes' object is not callable
Run Code Online (Sandbox Code Playgroud) 我有一个html表单,使用for循环显示数据.
<tbody id="table">
{% for sku, lid, stk, mrp, sp, stts in product_data %}
<tr>
<td>
<a class="btn-link" href="/product/product.html" value="{{sku}}">{{sku}}</a>
</td>
<td>{{lid}}</td>
.....
Run Code Online (Sandbox Code Playgroud)
此代码使用for循环在表中打印数据,在表的第一个colyumn中有链接.
该链接指向一个新页面,我希望显示一些数据.
现在显示的数据是从mongodb数据库动态生成的.我想当我点击链接时它将值作为参数传递给django视图,因此可以获取包含参数的数据并在下一页显示它.怎么做?
我的views.py:
from django.shortcuts import render
from django.http import HttpResponse
from inventory.models import GetProductData
def inventory(request):
pd = GetProductData().skuData()
sku = pd[0]
listing_id = pd[1]
stock_count = pd[2]
mrp = pd[3]
status = pd[5]
selling_price = pd[4]
product_data = zip(sku, listing_id, stock_count, mrp, selling_price, status)
context_dict = {'product_data':product_data}
return render(request, 'inventory/inventory.html', context_dict)
def product(request):
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用django-rest-framework和django-rest-auth通过tivix 实现身份验证(链接到文档).我使用django shell创建了一个用户:
from django.contrib.auth.models import User
user = User.objects.create_user(username='foo', email='foo@bar.com', password='bar')
user.save()
Run Code Online (Sandbox Code Playgroud)
然后根据文档我使用django-rest-authlike(终端命令)登录用户:
curl -X POST -d "username=foo&password=bar&email=foo@bar.com" http://127.0.0.1:8000/rest-auth/login/
Run Code Online (Sandbox Code Playgroud)
它返回了一个令牌,我知道用户已经过身份验证.
现在我使用django-rest-auth文档中描述的方法注销,我仍然可以看到数据库中存在的令牌.然后我再次登录,它返回了与密钥相同的令牌.
因此,每次用户注销时,都会以任何方式删除令牌或更好的令牌.此外,文档中没有提及令牌本身是否会在经过一定时间后过期(自动删除).
如果不可能这样做,我怎样才能删除这两种情况下的令牌?
编辑:登录和退出代码
urls.py(主要):
url(r'^rest-auth/', include('rest_auth.urls')),
Run Code Online (Sandbox Code Playgroud)
settings.py:
INSTALLED_APPS = [
...
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
...
]
Run Code Online (Sandbox Code Playgroud)
登录CURL命令:( GIVEN ABOVE).登录命令响应:
{u'key': u'e41f0a1c2f5e55569df1c41d1d5d4efb77beddee'}
Run Code Online (Sandbox Code Playgroud)
注销CURL命令:
curl -X POST -d "key=e41f0a1c2f5e55569df1c41d1d5d4efb77beddee" http://127.0.0.1:8000/rest-auth/logout/
Run Code Online (Sandbox Code Playgroud)
退出响应:
{u'success': u'Successfully logged out.'}
Run Code Online (Sandbox Code Playgroud) authentication django django-rest-framework django-rest-auth
您好我正在编写一个查询以在表中插入值.它给了我一个错误.
我的Qyery
INSERT INTO res_partner(
name,
company_id,
create_date,
street,
city,
display_name,
zip,
supplier,
ref,
is_company,
customer,
street2,
employee,
write_date,
active,
write_uid,
lang,
create_uid,
notify_email)
VALUES(
(SELECT shipping_address_name FROM temp_unicom),
1,
LOCALTIMESTAMP,
(SELECT shipping_address_line_1 FROM temp_unicom;),
(SELECT shipping_address_city FROM temp_unicom),
(SELECT shipping_address_name FROM temp_unicom),
(SELECT shipping_address_pincode FROM temp_unicom),
FALSE,
(Select sale_order_item_code FROM temp_unicom),
FALSE,
TRUE,
(SELECT shipping_address_line_2 FROM temp_unicom),
FALSE,
LOCALTIMESTAMP,
TRUE,
1,
'en_US',
1,
'always');
Run Code Online (Sandbox Code Playgroud)
错误:
错误:用作表达式的子查询返回的多行
**********错误**********
错误:用作表达式SQL状态的子查询返回的多行:21000
我知道每个select子查询返回多行,但我不知道如何纠正它.我在大约15000行temp_unicom的表,我试图从插入数据temp_unicom到res_partner.
我有一个带有多个按钮的表单,它映射到 django 视图。喜欢:
<form name="demo-form" method="POST" action="{% url 'internalManifest' %}">
<button class="btn btn-success" name="start_manifest">Start Manifest</button>
<button class="btn btn-success" name="close_manifest">Close Manifest</button>
</form>
Run Code Online (Sandbox Code Playgroud)
以上两个按钮从models.py 调用两种不同的方法,但我可以从单个django 视图中调用。喜欢:
Django 视图:
if request.method == 'POST' and 'start_manifest' in request.POST:
call_function1()
if request.method == 'POST' and 'close_manifest' in request.POST:
call_function2()
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何根据按钮的名称将两个不同的 ajax 请求发送到同一个视图函数?
假设我有 2 个 ajax 请求。两者都从models.py 调用不同的方法。我想根据按钮名称发送 ajax 调用。喜欢:
jQuery(document).ready(function($){
$('[name="form_internal_manifest"]').on('submit', function(event){
event.preventDefault();
$.ajax({
url : "/internalmanifest/",
type : "POST",
...
jQuery(document).ready(function($){
$('[name="form_internal_manifest"]').on('submit', function(event){
event.preventDefault();
$.ajax({
url : "/internalmanifest/",
type : "POST",
...
Run Code Online (Sandbox Code Playgroud) 我有一个类:
class TestClass(object):
def __init__(self, *args):
try:
## check some condition
except:
return
## Should exit class
def do_something_else(self):
...
def return_something(self):
## return something
Run Code Online (Sandbox Code Playgroud)
现在我试图像这样称呼这个班级:
TestClass(arg1, arg2, ..).do_something_else()
somthing = TestClass(arg1, arg2, ..).return_something()
Run Code Online (Sandbox Code Playgroud)
当我执行第一个命令时,我的条件失败并引发异常。我想要的是,如果__init__函数中发生某些异常,则do_something_method不应调用并且控制流应转到第二个命令。
在第二个命令中,满足所有条件并且return_something应该调用该函数。
我怎样才能做到这一点?
我正在尝试将 switchery 应用到文档中的所有元素classname="demo-sw"。
我可以通过类名将其应用于一个元素。喜欢:
<input id="demo1" class="switchery switchery-primary" type="checkbox" data-switchery="true">
new Switchery(document.document.getElementById('demo1'), {color:'#489eed'});
Run Code Online (Sandbox Code Playgroud)
我如何将它应用于具有 classname 的所有元素demo-sw。
我试过:
$('.demo-sw').each(function(i, obj) {
new Switchery($(this), {color:'#489eed'})
});
Run Code Online (Sandbox Code Playgroud)
和
$('.demo-sw').each(function(i, obj) {
new Switchery(i, {color:'#489eed'})
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用。