我在尝试保存Django User模型实例时遇到TransactionManagementError,并在其post_save信号中,我保存了一些将用户作为外键的模型.
在使用信号时,上下文和错误与此问题django TransactionManagementError非常相似
但是,在这种情况下,错误仅在单元测试时发生.
它在手动测试中运行良好,但单元测试失败.
有什么我想念的吗?
以下是代码段:
views.py
@csrf_exempt
def mobileRegister(request):
if request.method == 'GET':
response = {"error": "GET request not accepted!!"}
return HttpResponse(json.dumps(response), content_type="application/json",status=500)
elif request.method == 'POST':
postdata = json.loads(request.body)
try:
# Get POST data which is to be used to save the user
username = postdata.get('phone')
password = postdata.get('password')
email = postdata.get('email',"")
first_name = postdata.get('first_name',"")
last_name = postdata.get('last_name',"")
user = User(username=username, email=email,
first_name=first_name, last_name=last_name)
user._company = postdata.get('company',None)
user._country_code = postdata.get('country_code',"+91")
user.is_verified=True …Run Code Online (Sandbox Code Playgroud) 我正在尝试让QML使用FB Javascript SDK与FB图形API进行交互.
我在WebView元素中加载此HTML:
html: "<script>console.log(\"This is in WebKit!\"); window.FB.init();</script>"
Run Code Online (Sandbox Code Playgroud)
我还在WebView中创建了一个名为FB的JS窗口对象:
javaScriptWindowObjects: QtObject {
WebView.windowObjectName: "FB"
}
Run Code Online (Sandbox Code Playgroud)
但是只要调用window.FB.init(),它就会抛出一个错误:
ReferenceError: Can't find variable: window
Run Code Online (Sandbox Code Playgroud)
我正在使用的另一种方法是使用Component.onComplete加载FB.init()函数
function startupFunction() {
console.log("This call is in QML!");
FB.init({
appId:'XXXXXXXXXXXXX', cookie:true,
status:true
});
console.log(FB);
}
Component.onCompleted: startupFunction();
Run Code Online (Sandbox Code Playgroud)
但我得到的错误是:
TypeError: Result of expression 'FB.init' [undefined] is not a function
Run Code Online (Sandbox Code Playgroud)
这是完整的QML:
import QtQuick 1.0
import "fb.js" as FB
import QtWebKit 1.0
Rectangle {
width: 360
height: 360
Text {
text: "Hello World"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: …Run Code Online (Sandbox Code Playgroud) 我有一系列定义网站结构的链接。从这些链接下载图像时,我想同时将下载的图像放置在与网站结构类似的文件夹结构中,而不仅仅是重命名它(如Scrapy image download 如何使用自定义文件名中的回答)
我的代码是这样的:
class MyImagesPipeline(ImagesPipeline):
"""Custom image pipeline to rename images as they are being downloaded"""
page_url=None
def image_key(self, url):
page_url=self.page_url
image_guid = url.split('/')[-1]
return '%s/%s/%s' % (page_url,image_guid.split('_')[0],image_guid)
def get_media_requests(self, item, info):
#http://store.abc.com/b/n/s/m
os.system('mkdir '+item['sku'][0].encode('ascii','ignore'))
self.page_url = urlparse(item['start_url']).path #I store the parent page's url in start_url Field
for image_url in item['image_urls']:
yield Request(image_url)
Run Code Online (Sandbox Code Playgroud)
它创建了所需的文件夹结构,但是当我深入进入文件夹时,我发现文件已被放错位置。
我怀疑这种情况正在发生,因为“get_media_requests”和“image_key”函数可能会异步执行,因此“page_url”的值在“image_key”函数使用之前会发生变化。
我有5个div带属性的元素data-role="content"
我选择所有这些
a = $('div[data-role=content]')
Run Code Online (Sandbox Code Playgroud)
它回来了[object HTMLDivElement].
为了隐藏所有div元素,我迭代a并隐藏每个元素
<script>
$.each(a, function(index, value) {
if (value) {
alert(typeof(value));
value.hide();
}
})
</script>?
Run Code Online (Sandbox Code Playgroud)
但它返回错误....
TypeError: Result of expression 'a.hide' [undefined] is not a function
Run Code Online (Sandbox Code Playgroud)
另一方面,如果我选择一个id为div的div:
a = $('div[id=content1]')
Run Code Online (Sandbox Code Playgroud)
它给了我一个:
[object Object]
Run Code Online (Sandbox Code Playgroud)
隐藏功能a.hide()适用于该情况.
问题是:"如何[object Object]一次选择所有元素?" 或者,"我怎样才能转换[object HTMLDivElement]成[object Object]?"
python ×2
django ×1
facebook ×1
javascript ×1
jquery ×1
qml ×1
qt ×1
scrapy ×1
unit-testing ×1