我需要将click事件绑定到<a>FuelUX DataGrid列中的标记,这些标记通过自定义格式化程序动态添加.
格式化程序正在按预期工作,但是,我不确定如何绑定click事件处理程序.我宁愿以不引人注目的方式这样做.
DataGrid应该具有"已加载"事件挂钩,但是没有关于如何使用此事件的示例.有人可以请我举个例子吗?谷歌对我来说很短暂.
我能找到的唯一参考是在datagrid.js的163上:
self.$element.trigger('loaded');
Run Code Online (Sandbox Code Playgroud)
我假设这意味着我需要在对象上定义一个"加载"函数,但在哪里/如何?我的DataGrid是:
$('#jobs').datagrid({
dataSource: dataSource,
itemsText: 'Available Positions',
itemText: 'Available Position';
});
Run Code Online (Sandbox Code Playgroud) 每次创建新用户时,如何使用一些默认/初始数据填充下表?我知道这个https://docs.djangoproject.com/en/dev/howto/initial-data/,但这仅在我创建模型时有效。在这里,我想在创建新用户时插入一些默认条目。
此外,当我创建一个新用户时,如何自动将他添加到具有静态组 ID 的给定组?
模型.py
from django.db import models
from django.contrib.auth.models import User
class Category(models.Model):
name = models.CharField(max_length=50)
user = models.ForeignKey(User)
class Feed(models.Model):
url = models.URLField()
name = models.CharField(max_length=50)
created = models.DateTimeField(auto_now_add=True)
description = models.TextField(blank=True)
category = models.ForeignKey(Category)
user = models.ForeignKey(User)
Run Code Online (Sandbox Code Playgroud)
视图.py
def signup(request):
if request.method == 'POST':
form = UserCreationForm1(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect("/accounts/login")
else:
form = UserCreationForm1()
return render(request, "registration/signup.html", {
'form': form,
})
Run Code Online (Sandbox Code Playgroud)
表格.py
class UserCreationForm1(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用Tornado Web Server来提供静态文件,但是当我运行服务器时,静态文件会出现404错误:
[I 140715 17:16:50 wsgi:358] 200 GET /myapp/index/ (127.0.0.1) 99.01ms
[W 140715 17:16:50 wsgi:358] 404 GET /static/logo_small_white.png (127.0.0.1) 5.68ms
[I 140715 17:17:04 wsgi:358] 200 GET /myapp/index/ (127.0.0.1) 6.02ms
[W 140715 17:17:05 wsgi:358] 404 GET /static/logo_small_white.png (127.0.0.1) 5.05ms
Run Code Online (Sandbox Code Playgroud)
这是我用来启动服务器的代码块:
#!/usr/bin/env python
# Run this with
# PYTHONPATH=. DJANGO_SETTINGS_MODULE=testsite.settings testsite/tornado_main.py
# Serves by default at
# http://localhost:8080/hello-tornado and
# http://localhost:8080/hello-django
from tornado.options import options, define, parse_command_line
import django.core.handlers.wsgi
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.wsgi
import os
define('port', type=int, …Run Code Online (Sandbox Code Playgroud) 我读过,成功处理发布数据后,您应该使用 HttpResponseRedirect 重定向到另一个页面。我正在构建一个用于学习目的的 URL 缩短器,views.py 中的代码如下所示:(不起作用)
def makeurl(request):
# get url from form
post_url = request.POST['url']
# shorten the url and have the short code returned
shortened_url = shorten_url(post_url)
return HttpResponseRedirect('create')
def create(request):
return render(request, 'shorturl/create.html',
{'shortened_url': shortened_url})
Run Code Online (Sandbox Code Playgroud)
当提交表单以缩短输入 URL 时,将调用“makeurl”,其中计算并返回缩短的 URL (shortened_utl)。然后,我调用“create”,这将呈现需要向用户显示“shortened_url”的页面。
问题是,如果我要使用 HttpResponseRedirect,我无法将“shortened_url”变量传递给要渲染的“create”视图。有人可以建议我这个吗?我是 django 新手,干杯
我的Celery任务没有在我的Django 1.7/Python3项目的后台执行.
# settings.py
BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULTBACKEND = BROKER_URL
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_ALWAYS_EAGER = False
Run Code Online (Sandbox Code Playgroud)
我celery.py在我的根应用程序模块中有这样的:
from __future__ import absolute_import
import os
import django
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_app.settings')
django.setup()
app = Celery('my_app')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
Run Code Online (Sandbox Code Playgroud)
并__init__.py在根模块中加载应用程序:
from __future__ import absolute_import
from .celery import app as celery_app
Run Code Online (Sandbox Code Playgroud)
我的任务在我的app模块的tasks.py文件中设置为共享任务:
from __future__ import absolute_import
from celery import shared_task
@shared_task
def update_statistics(profile, category):
# more code
Run Code Online (Sandbox Code Playgroud)
我将任务称为一个组:
. . .
job = group([update_statistics(f.profile, …Run Code Online (Sandbox Code Playgroud) 我的大多数Django模型使用相同的User Mixin,因此我想动态创建related_name该字段.
我希望它是类名,在主模型的元类中TestModel成为test_models甚至可能是一个集合名称.
我看过了,self__class__.__name__但这给了我User类的名字.
是否有可能做下面的事情,如果是这样的话......
class User(models.Model):
user = models.ForeignKey(USER, related_name=META.related_name)
class Meta:
abstract = True
class TestModel(User):
title = models.CharField(max_length=80)
class Meta:
related_name = "test_model"
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个共享服务来使用 Observable 在组件之间进行通信,使用:http : //blog.angular-university.io/how-to-build-angular2-apps-using-rxjs-observable-data-services -避免陷阱/作为指南:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable()
export class ModalService {
private _isOpen: BehaviorSubject<boolean> = new BehaviorSubject(false);
public isOpen: Observable<boolean> = this._isOpen.asObservable();
openModal() {
this._isOpen.next(true);
}
closeModal() {
this._isOpen.next(false);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的组件中,我订阅了isOpen,它在订阅时收到一个值:
. . .
ngOnInit(): void {
this.subscription = this.modalService.isOpen.subscribe(state => {
console.log('`isOpen` in subscription', state);
});
}
Run Code Online (Sandbox Code Playgroud)
但是,当我.openModal()在共享服务实例上触发时,订阅者永远不会收到新值。我究竟做错了什么?
我的逻辑是,通过使用行为主题,订阅者将收到一个初始值false,然后我可以更改来自其他具有共享服务实例的组件的单击值。
我在上传到正确的文件夹时遇到了一些困难。如果我指定:
cloudinary.uploader.upload(filePath, {
folder: 'test-directory'
});
Run Code Online (Sandbox Code Playgroud)
我正在关注节点集成指南:http : //cloudinary.com/documentation/image_upload_api_reference#upload
我提前创建了“测试目录”。图像上传成功,但总是进入我的媒体库的根目录。
我在我的帐户设置中启用了“自动创建文件夹”。
这是来自 Cloudinary 的示例上传响应:
{
public_id: 'we1yjvlpxc1qtuf1oaqe',
version: 1503236713,
signature: '37edbc2b19ea72b75298acce8075f9e8ddb12d09',
width: 675,
height: 37,
format: 'jpg',
resource_type: 'image',
created_at: '2017-08-20T13:45:13Z',
tags: [],
bytes: 602,
type: 'upload',
etag: 'b5522ae652340881b213c46c035d0aed',
url: 'http://res.cloudinary.com/alsoicode/image/upload/v1503236713/we1yjvlpxc1qtuf1oaqe.jpg',
secure_url: 'https://res.cloudinary.com/alsoicode/image/upload/v1503236713/we1yjvlpxc1qtuf1oaqe.jpg',
original_filename: 'test_r6_c1'
}
Run Code Online (Sandbox Code Playgroud)
我也尝试将文件夹名称添加到public_id选项中,但这也不起作用。
我究竟做错了什么?
我在为Angular 2 Material实现自定义主题时遇到很多困难。我一直在遵循以下指南:
并为我的颜色生成了自定义调色板。例如我的“原色”颜色:
$dz-primary: (
50 : #e8ebee,
100 : #c6cdd4,
200 : #a0acb7,
300 : #7a8a9a,
400 : #5e7184,
500 : #41586e,
600 : #3b5066,
700 : #32475b,
800 : #2a3d51,
900 : #1c2d3f,
A100 : #82baff,
A200 : #4f9eff,
A400 : #1c83ff,
A700 : #0275ff,
contrast: (
50 : #000000,
100 : #000000,
200 : #000000,
300 : #000000,
400 : #ffffff,
500 : #ffffff,
600 : #ffffff,
700 : #ffffff,
800 : #ffffff,
900 …Run Code Online (Sandbox Code Playgroud) 当为控制器编写单元测试时,Nest 无法解析我的 Mongoose 模型依赖项:
Nest 无法解析 UsersService 的依赖关系(?)。请确保索引 [0] 处的参数 USER_MODEL 在 _RootTestModule 上下文中可用。
Run Code Online (Sandbox Code Playgroud)Potential solutions: - If USER_MODEL is a provider, is it part of the current _RootTestModule? - If USER_MODEL is exported from a separate @Module, is that module imported within _RootTestModule? @Module({ imports: [ /* the Module containing USER_MODEL */ ] })
我的模型是通过 users.service.ts 中的服务构造函数注入的:
Potential solutions:
- If USER_MODEL is a provider, is it part of the current _RootTestModule?
- If USER_MODEL is exported from a …Run Code Online (Sandbox Code Playgroud) django ×5
python ×3
node.js ×2
angular ×1
celery ×1
cloudinary ×1
django-forms ×1
django-views ×1
fuelux ×1
http ×1
javascript ×1
jquery ×1
nestjs ×1
python-2.7 ×1
rxjs ×1
sass ×1
tornado ×1
typescript ×1