我服务器的响应如下:
[{"coreGoalId":1,"title":"Core goal 1","infrastructure":"Sample Infrastructure","audience":"People","subGoals":null,"benefits":[{"benefitId":1,"what":"string","coreGoalId":1}],"effects":null,"steps":null,"images":[{"imagelId":1,"base64":"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcU\nFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgo\nKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wgARCAIWAe4DASIA\nAhEBAxEB/8QAHAABAAIDAQEB"}]}]
Run Code Online (Sandbox Code Playgroud)
我正在尝试显示其中返回的base64图像.
在我的组件中:
ngOnInit() {
this.homeService.getGoals()
.subscribe(
goals => this.coreGoals = goals,
error => this.errorMessage = <any>error);
}
Run Code Online (Sandbox Code Playgroud)
然后在模板中:
<ul>
<li *ngFor="let goal of coreGoals">
{{goal.title}}
<img [src]="'data:image/jpg;base64,'+goal.images[0].base64 | safeHtml" />
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
safeHtml是我创建的管道,如下所示:
import { Pipe } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({name: 'safeHtml'})
export class SafeHtml {
constructor(private sanitizer:DomSanitizer){}
transform(html) {
return this.sanitizer.bypassSecurityTrustHtml(html);
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我Required a safe URL, got a HTML错误.这里出了什么问题?如果我从那里删除管道<img />它说不安全的网址.
我正在使用django-rest-auth和allauth在我的django应用程序中登录和注册.我没有为登录或注册编写任何额外的单行代码.使用emailid和提供的密码注册成功.
我不使用用户名进行身份验证,而是使用电子邮件
在我可浏览的注册api中,我得到以下内容:
除了这些字段,我想要first_name和last_name(默认的auth_user表有这些列),这样我新创建的auth_user也会设置这些字段以及电子邮件和散列密码.
我怎样才能做到这一点?这个可浏览的表单本身并不那么重要,但能够存储first_name和last_name是我主要需要的.
django django-rest-framework django-allauth django-rest-auth
我有一个django项目,我在其中使用Django-rest-auth进行身份验证.我想使用带密码的电子邮件来验证用户身份,而不是用户名+密码.
我在settings.py中有以下设置,但它对我没有任何作用:
REST_SESSION_LOGIN = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'EMAIL'
ACCOUNT_EMAIL_VERIFICATION = 'optional'
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现它?
python django django-rest-framework django-allauth django-rest-auth
我正在尝试编写一个switch语句,但它似乎没有按我的意愿工作.
getExerciseDescription(exerciseId, intensity_level){
alert(exerciseId + " " + intensity_level)
switch (exerciseId && intensity_level) {
case (1 && 1):
this.header="Exercise 1 Level 1";
this.instructions="Exercise 1 Level 1";
break;
case (1 && 2):
this.header="Exercise 1 Level 2";
this.instructions="Exercise 1 Level 2";
break;
case (2 && 1):
this.header="Exercise 2 Level 1";
this.instructions="Exercise 2 Level 1";
break;
case (2 && 2):
this.header="Exercise 2 Level 2";
this.instructions="Exercise 2 Level 2";
break;
default:
this.header="Default";
this.instructions="Default";
break;
}
return new Popup(this.header, this.instructions);
}
Run Code Online (Sandbox Code Playgroud)
警报给出2和1,但返回值为(1 && 1).为什么会这样?我怎样才能解决这个问题?
我从网站上安装了MySQL和Workbench.我有一个django项目的requirements.txt:
Django==1.11.12
djangorestframework==3.8.2
django-cors-headers==2.2.0
drfdocs==0.0.11
mysql-python==1.2.5
django-rest-auth==0.9.3
django-allauth==0.35.0
nltk==3.2.5
django-extensions==2.0.7
pyparsing==2.2.0
pydot==1.2.4
Run Code Online (Sandbox Code Playgroud)
我跑的时候
pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
我收到了一个错误mysql_config not found.为了解决这个问题我跑了
PATH=$PATH:/usr/local/mysql/bin
Run Code Online (Sandbox Code Playgroud)
它现在抛出
_mysql.c:44:10: fatal error: 'my_config.h' file not found
#include "my_config.h"
^~~~~~~~~~~~~
1 error generated.
error: command 'cc' failed with exit status 1
----------------------------------------
Command ""/Users/nitish/gitProjects/Vision Backlog/vb_env/bin/python" -u -c "import setuptools, tokenize;__file__='/private/var/folders/ql/_w2_rlvs2351pdcnzhn04sf40000gn/T/pip-install-M4ue9E/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/ql/_w2_rlvs2351pdcnzhn04sf40000gn/T/pip-record-7OCzf1/install-record.txt --single-version-externally-managed --compile --install-headers "/Users/nitish/gitProjects/Vision Backlog/vb_env/include/site/python2.7/mysql-python"" failed with error code 1 in /private/var/folders/ql/_w2_rlvs2351pdcnzhn04sf40000gn/T/pip-install-M4ue9E/mysql-python/
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
更新:跟随下面的解决方案抛出:
Collecting MySQL-python
Using cached …Run Code Online (Sandbox Code Playgroud) 我有一个模特:
export class CoreGoalModel {
constructor(
public title: string,
public image: string,
){}
}
Run Code Online (Sandbox Code Playgroud)
我的服务:
getGoals(): Observable<CoreGoalModel[]> {
let headers = new Headers({ 'Access-Control-Allow-Origin': '*' });
let options = new RequestOptions({ headers: headers });
return this.http.get(this.base_url + 'coregoal', options)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
return body.data || { };
}
Run Code Online (Sandbox Code Playgroud)
然后在我的组件中:
ngOnInit() {
this.homeService.getGoals()
.subscribe(
goals => this.coreGoals = goals,
error => this.errorMessage = <any>error);
}
Run Code Online (Sandbox Code Playgroud)
然后我在我的模板中将其绑定为:
<ul>
<li *ngFor="let goal of coreGoals">
{{goal.title}} …Run Code Online (Sandbox Code Playgroud) 在我的Ionic 2应用程序中,我有一个消耗服务的组件,该服务使http GET获取一些数据.然后我的组件调用此服务,当数据可用时,它会设置并显示它.
它看起来如下:
export class FarmList implements OnInit {
items: Object;
constructor(public testService: TestService, public nav: NavController){
}
ngOnInit(){
this.getData()
}
getData(){
let loading = Loading.create({
content: 'Please wait..',
spinner: 'crescent'
})
this.nav.present(loading)
this.testService.fetchData().then(data => this.items = data)
}
...
}
Run Code Online (Sandbox Code Playgroud)
当我的组件以异步方式获取数据时,我正在尝试loader旋转,一旦数据可用,我希望它loader消失.
但是,使用我当前的代码,即使数据可用并显示,微调器也会继续旋转,如屏幕截图所示:
getData()是进行服务调用的方法.
我怎样才能解决这个问题?这是实现加载器的正确方法吗?
我已经使用以下设置对我现有的 angular cli 应用程序进行了docker化:
根级dockerfile:
# Create a new image from the base nodejs 7 image.
FROM node:7
# Create the target directory in the imahge
RUN mkdir -p /usr/src/app
# Set the created directory as the working directory
WORKDIR /usr/src/app
# Copy the package.json inside the working directory
COPY package.json /usr/src/app
# Install required dependencies
RUN npm install
# Copy the client application source files. You can use .dockerignore to exlcude files. Works just as .gitignore does.
COPY . …Run Code Online (Sandbox Code Playgroud) 我正在使用DRF和登录/注册我正在使用Django-rest-auth.
注册成功但是,额外的字段不会与username,first_name,last_name和password一起保存.
我的模特:
class UserManager(BaseUserManager):
def _create_user(self, username, email, password, is_staff, is_superuser, address, **extra_fields):
now = timezone.now()
if not username:
raise ValueError(_('The given username must be set'))
email = self.normalize_email(email)
user = self.model(username=username, email=email,
is_staff=is_staff, is_active=True,
is_superuser=is_superuser, last_login=now,
date_joined=now, address=address, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, username, email=None, password=None, **extra_fields):
return self._create_user(username, email, password, False, False, True,
**extra_fields)
def create_superuser(self, username, email, password, **extra_fields):
user=self._create_user(username, email, password, True, True,
**extra_fields)
user.is_active=True
user.save(using=self._db)
return user
class User(AbstractBaseUser, PermissionsMixin): …Run Code Online (Sandbox Code Playgroud) 我有一个包含多个 GitHub 链接的表。我想用 GitHub 符号替换所有这些链接。我使用 fontawesome 来渲染符号:
\usepackage{fontawesome}
\faGitSquare
Run Code Online (Sandbox Code Playgroud)
我不知道如何才能只用这样的符号替换 GitHub 链接?也许修改href?但不知道该怎么做。
angular ×4
django ×4
python ×2
typescript ×2
angular-cli ×1
docker ×1
ionic2 ×1
ionic3 ×1
javascript ×1
latex ×1
pip ×1