我正在自学AJAX来AJAX化我的网站.在我的模板中,我有以下JS代码从视图中获取一些JSON数据,然后将数据附加到div.
function filter(type) {
$.getJSON(
'/activity_stream/global-activity-stream/',
{xhr: "true", filter: type},
function(data) {
$('.mainContent').children().remove();
$(data).appendTo('.mainContent');
});
}
$(".btn").click(function () {
filter("recent");
});
}
Run Code Online (Sandbox Code Playgroud)
我认为我的观点是返回正确的JSON,但现在数据没有添加到.mainContentdiv.
它给出了这个错误:
未捕获的TypeError:无法读取未定义的属性"ownerDocument".
我正在使用MySQL DB构建一个django应用程序.当我第一次运行'python manage.py migrate'时,会创建一些表,然后会出现一些错误.带来的错误是:
django.db.utils.IntegrityError:(1215,'无法添加外键约束')
当我运行这个MySQL命令时 -
SHOW ENGINE INNODB状态\ G,
我明白了>>>
2015-02-17 14:33:17 7f10891cf700 Error in foreign key constraint of table movie_store/#sql-4f1_66:
FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`):
Cannot resolve table name close to:
(`id`)
Run Code Online (Sandbox Code Playgroud)
完整的追溯是:
Creating tables...
Creating table users
Creating table merchant
Creating table celery_taskmeta
Creating table celery_tasksetmeta
Creating table djcelery_intervalschedule
Creating table djcelery_crontabschedule
Creating table djcelery_periodictasks
Creating table djcelery_periodictask
Creating table djcelery_workerstate
Creating table djcelery_taskstate
Creating table post_office_email
Creating table post_office_log
Creating table post_office_emailtemplate
Creating table …Run Code Online (Sandbox Code Playgroud) 我正在使用django 1.7,我刚刚添加了一个自定义用户模型.当我运行任何一个python3 manage.py makemigrations或python3 manage.py migrate我得到错误:TypeError: __init__() got an unexpected keyword argument 'preserve_default'.添加新的自定义用户模型后出现此问题.完整的追溯是:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/migrate.py", line 63, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 17, in __init__
self.loader …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 django rest 框架实现多个嵌套的可写序列化程序。我已经阅读了可用的文档http://www.django-rest-framework.org/api-guide/serializers/#writable-nested-representations
我已经能够对一层嵌套执行此操作,但是当有多个嵌套时会出现问题。例如,我有这 3 个序列化程序:
class FarmerSerializer(serializers.ModelSerializer):
dob = serializers.DateField(write_only=True)
gender = serializers.CharField(write_only=True)
farms = FarmSerializer(required=False, many=True)
class Meta:
...
def create(self, validated_data):
# check if nested objects were provided, in particular farms
farms = validated_data.pop('farms', None)
farmer = Farmer(**validated_data)
farmer.added_by_id = validated_data.get('added_by_id')
farmer.save()
if farms is not None:
for farm in farms:
new_farm = Farm.objects.create(farmer=farmer, added_by=farmer.added_by, **farm)
# check for blocks -- fails
blocks = farm.pop('farm_blocks', None)
if blocks is not None:
for block in blocks: …Run Code Online (Sandbox Code Playgroud) 我使用Qt设计器创建了一个主窗口,其中包含一个tabwidget。我的问题是,当窗口最大化时,tabwidget仍保持其原始大小-因此在其右侧留有许多灰色空间。
我希望主窗口始终处于最大化状态,那么如何调整Tabwidget的大小以占据更多空间?我可以在以下代码中添加些什么来实现此目的?
self.tabWidget = QtGui.QTabWidget(self.centralwidget)
self.tabWidget.setEnabled(True)
self.tabWidget.setGeometry(QtCore.QRect(20, 40, 601, 501))
self.tabWidget.setTabPosition(QtGui.QTabWidget.North)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
Run Code Online (Sandbox Code Playgroud) 我正在使用带快递和把手的Node.我有一个登录表单,应该向用户显示登录错误消息.我的代码如下:验证(使用护照):
...
else if (password != user.password) {
return done(null, false, req.flash('message', 'Wrong password'));
...
Run Code Online (Sandbox Code Playgroud)
在路线我得到了这个:
app.post('/sign-in', passport.authenticate('local', {
successRedirect : '/', // redirect to the home page
failureRedirect : '/sign-in', // redirect back to the signup page if there is an error
failureFlash : true // allow flash messages
}));
Run Code Online (Sandbox Code Playgroud)
然后渲染我的车把模板,
app.get('/sign-in', function(req, res) {
res.render("signin.handlebars", {layout: 'users.handlebars', action: 'Sign in', message: req.flash('message'),
csrf: 'CSRF token goes here' });
})
Run Code Online (Sandbox Code Playgroud)
问题是,输入错误密码时,不会按要求显示flash消息.
编辑:我的快递设置是:
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.set('models', __dirname …Run Code Online (Sandbox Code Playgroud) 我有2个django应用程序,即主要和authtools.我跑的时候
python manage.py migrate
,我得到一个CircularDependencyError:
raise CircularDependencyError(", ".join("%s.%s" % n for n in cycle))
django.db.migrations.graph.CircularDependencyError: main.0001_initial, authtools.0001_initial
Run Code Online (Sandbox Code Playgroud)
在我的设置文件中,我将AUTH_USER_MODEL定义为:AUTH_USER_MODEL = 'authtools.User'.创建的迁移文件如下所示:对于authtools应用程序,它将依赖关系显示为:
dependencies = [
('main', '__first__'),
('auth', '0001_initial'),
]
Run Code Online (Sandbox Code Playgroud)
而对于主要应用程序,depandancies显示为:
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
Run Code Online (Sandbox Code Playgroud)
可能有什么不对?