我有一个表单,允许我使用js添加到多列表.我希望能够将该列表中的所有数据发布到我的瓶子服务器,但我无法获得任何数据.如何将我的语句中的所有项目发布到server.py?发布后如何访问此帖子数据?
相关代码:
server.py:
@bottle.route('/saveList', method='POST')
def save_list():
forms = bottle.request.get('the_list')
print forms # returns 'None'
return bottle.redirect('/updatelist') # just redirects to the same page with a new list
Run Code Online (Sandbox Code Playgroud)
list.tpl
<select multiple="multiple" id="the_list" name="the_list">
%for item in my_ list:
<option>{{item}}</option>
%end
</select>
Run Code Online (Sandbox Code Playgroud)
编辑:
我试图获取整个列表,而不仅仅是选定的值.用户通过textfield,button和JS添加到multi; 所以我想得到所有的值(或所有新的值).
编辑2:
我使用提供的答案和一些js来获得所需的结果:
$('.add_to_the_list').click(function (e) {
...
var new_item = $('<option>', {
value: new_item_str,
text: new_item_str,
class: "new_item" // the money-maker!
});
...
function selectAllNewItem(selectBoxId) {
selectBox = document.getElementById(selectBoxId);
for (var i = 0; i < selectBox.options.length; …Run Code Online (Sandbox Code Playgroud) 在database.yml你可以有一个默认的环境,并有其他的继承:
development: &default
adapter: postgresql
database: dev_development
test: &test
<<: *default
database: test_test
production:
<<: *default
database: test_production
Run Code Online (Sandbox Code Playgroud)
你能在secrets.yml做到这一点吗?你应该?
我试图做一个继承项目,我收到这个错误:
/tmp/ccw1aT69.o: In function `main':
main.cpp:(.text+0x15): undefined reference to `Derived::Derived(int)'
/tmp/ccw1aT69.o: In function `Derived::~Derived()':
main.cpp:(.text._ZN20DerivedD2Ev[_ZN20DerivedD5Ev]+0x13): undefined reference to `vtable for Derived'
main.cpp:(.text._ZN20DerivedD2Ev[_ZN20DerivedD5Ev]+0x1f): undefined reference to `Base::~Base()'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
main.cpp中:
#include <iostream>
#include "Base.h"
#include "Derived.h"
int main() {
Derived intList(25);
}
Run Code Online (Sandbox Code Playgroud)
base.h:
#ifndef BASE_H
#define BASE_H
class Base {
public:
...
Base (const Base& otherList);
virtual ~Base();
protected:
int *list;
int length;
int maxSize;
};
#endif
Run Code Online (Sandbox Code Playgroud)
Base.cpp:
#include "Base.h"
#include …Run Code Online (Sandbox Code Playgroud) 我正在编写一个简单的脚本,将AD组成员身份从一个用户复制到另一个用户。我仅使用ActiveDirectory模块来执行此操作。
该脚本看起来可以正常工作,直到我尝试将组广告发布给用户为止。
码:
import-module ActiveDirectory
$templateUser = get-ADUser user1
$targetUser = getADUser user2
$groups =get-adprincipalgroupmembership $templateUser
$groups2 = get-ADPrincipalGroupMembership $targetUser
foreach($group in $groups) {
add-adGroupMember $group $targetUser
}
Run Code Online (Sandbox Code Playgroud)
错误:
Add-ADGroupMember : insufficient access rights to performt the operation
At line:9 char:18
+ FullyQualifiedErrorID : Insufficient access rights to perform the operation,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
Run Code Online (Sandbox Code Playgroud)
注意事项/想法:
我以普通用户身份登录,但以其他用户身份(我的管理员帐户)运行了Powershell。我不是本地管理员,但是我是域上的管理员。如果我启动AD工具并手动执行操作,则可以将用户添加到组中(我有权添加到那些组中)。
编辑:
以管理员身份运行powershell。
我正在尝试编写一个简单的 WebApp 来将文件上传到 MongoDB 数据库中。我可以上传文档的主题和对象的日期(作为字符串数据类型)。我现在正在尝试将实际文件上传到 MongoDB,但事实证明这很困难。我尝试了 MultipartFile,但它不会加载文件。然后我尝试将字符串获取到文件路径并产生空指针异常(可能是因为字符串路径指向本地资源,而不是在服务器上)。
如何使用 web 应用程序将文件上传到 MongoDB?我为所有的代码道歉,但我不知道我应该发布多少。
错误:
java.lang.NullPointerException
at java.io.File.<init>(File.java:251)
at com.jcdc.domain.FileUpload.setFile(FileUpload.java:34)
at com.jcdc.controller.DocumentController.create(DocumentController.java:43)
at com.jcdc.controller.DocumentController$$FastClassByCGLIB$$f5f3eaff.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.interceptor.CustomizableTraceInterceptor.invokeUnderTrace(CustomizableTraceInterceptor.java:256)
at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at com.jcdc.controller.DocumentController$$EnhancerByCGLIB$$6b66bfcf.create(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) …Run Code Online (Sandbox Code Playgroud) 在 Rails 中,我有这个 User 模型:
class User < ActiveRecord::Base
enum role: [:adult, :child, :admin]
after_initialize :set_default_role, :if => :new_record?
# belongs_to :spouse, :foreign_key => :spouse_id, :class_name => 'User', :inverse_of => :spouse
def set_default_role
self.role ||= :adult
end
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
def marry(user)
self.spouse = user
user.spouse = self
end
end
Run Code Online (Sandbox Code Playgroud)
我通过这次迁移添加了配偶:
class AddFieldsToUser < ActiveRecord::Migration
def change
# for marriages
add_column …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Heroku上部署ionic2应用程序。我看了这些站点:
并创建了一个server.js文件:
var express = require('express');
var app = express(); // create our app w/ express
var morgan = require('morgan'); // log requests to the console (express4)
var bodyParser = require('body-parser'); // pull information from HTML POST (express4)
var cors = require('cors');
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
// app.use(methodOverride());
app.use(cors());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", …Run Code Online (Sandbox Code Playgroud) 我的前端检查后端以查看访客模型是否存在.此调用适用于使用邮递员(POST到localhost:1337/visitor/exists数据:{'email': 'some@email.com'}).当我尝试让我的angular2服务进行相同的调用时,它会无声地失败.
这是我的服务:
@Injectable()
export class MyService {
private myUrl = 'localhost:1337/visitor/exists';
constructor(private http: Http) { }
checkVisitor(email :string): Observable<boolean> {
console.log('in myservice, checkvisitor; email: ', email); // this outputs
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let body = {'email': email};
console.log('body, ', body); // this also outputs
return this.http.post(this.myUrl, JSON.stringify(body), options)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
console.log('in service, extractData; res: ', …Run Code Online (Sandbox Code Playgroud) 我想测试将返回true或false作为响应的端点的使用。不'true'只是 的布尔值true。我正在使用该@angular/common/http/testing模块。对于我可以使用的其他响应值TestResponse.flush(value),但这不适用于boolean值。相反,测试模块抱怨
响应类型不支持自动转换为 JSON。
这是我的测试代码:
const FLUSH_OK = {status: 200, statusText: 'Ok'};
//.. describe...
it('should work', async(() => {
service.myFunction().subscribe((data) => { // my Function returns Observable<boolean>, the real endpoint returns a true/false boolean
expect(data).toEqual(true);
});
// this fails: Failed: Automatic conversion to JSON is not supported for response type.
httpMock.expectOne((req) => {
return req.url === MY_URL;
}).flush(true, FLUSH_OK);
// this also fails: Expected 'true' to …Run Code Online (Sandbox Code Playgroud) 我正在尝试制定一个简单的指令。加载图像时,img src 将设置为@Input()字符串字段。加载时,图像将设置为原始 src 值(或至少我尝试实现它的方式)。
我在这里使用了答案:https : //stackoverflow.com/a/38837619/843443 但它不是指令,因此在我使用图像的任何地方都需要进行一些更改。
我的第一次尝试:
加载 img.directive.ts:
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
@Directive({
selector: '[tohLoadingImg]'
})
export class LoadingImgDirective {
imgSrc: String;
@Input()
spinnerSrc: String;
constructor(private el: ElementRef) {
this.imgSrc = el.nativeElement.src;
el.nativeElement.src = this.spinnerSrc;
}
@HostListener('load') onLoad() {
this.el.nativeElement.src = this.imgSrc;
}
}
Run Code Online (Sandbox Code Playgroud)
从:
<img src="{{hero.imgUrl}}" alt="Random first slide">
Run Code Online (Sandbox Code Playgroud)
到:
<img src="{{hero.imgUrl}}" alt="Random first slide" [tohLoadingImg]="'/assets/ring.svg'">
Run Code Online (Sandbox Code Playgroud)
错误:
Can't bind to 'tohLoadingImg' since it isn't a known property …Run Code Online (Sandbox Code Playgroud) angular ×3
http ×2
boolean ×1
bottle ×1
c++ ×1
constructor ×1
file-upload ×1
heroku ×1
ionic2 ×1
java ×1
mocking ×1
mongodb ×1
node.js ×1
permissions ×1
powershell ×1
python ×1
rxjs ×1
spring-mvc ×1
typescript ×1