小编Bel*_*ter的帖子

调整屏幕大小时,bootstrap 4导航栏消失

我使用angular 2和bootstrap 4,navbar主页上有一个,但是当我将页面缩小到小于1000px时,文本就navbar消失了.

这是我的代码:

 <nav class="navbar navbar-expand-lg navbar-dark bg-info" style="padding: 1px; width: 100%">
    <!-- <a class="navbar-brand" routerLink='/index' style="padding-right: 5px">
    </a> -->
    <div class="navbar-inner">
      <div class="container">

        <!-- .btn-navbar is used as the toggle for collapsed navbar content -->
        <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
        <!-- Be sure to leave the brand out there if you want it shown -->
        <!-- <a class="brand" href="#">Project name</a> -->

        <div class="collapse navbar-collapse" >
          <div class="navbar-nav …
Run Code Online (Sandbox Code Playgroud)

html bootstrap-4 angular

4
推荐指数
1
解决办法
3333
查看次数

Django REST框架 - 类UserSerializer缺少"Meta.model"属性

我正在关注Django REST Framework 的教程,一直都很好,直到第4部分 - 身份验证和权限 - > 添加登录到Browsable API,我想浏览我通过url创建的用户http://localhost:8024/users/.

但我收到此错误消息:

AssertionError at /users/
Class UserSerializer missing "Meta.model" attribute
Request Method: GET
Request URL:    http://localhost:8024/users/
Django Version: 1.10
Exception Type: AssertionError
Exception Value:    
Class UserSerializer missing "Meta.model" attribute
Exception Location: C:\Python27\lib\site-packages\rest_framework\serializers.py in get_fields, line 976
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.11
Python Path:    
['D:\\github\\py2\\dj-rest\\tutorial',
 'C:\\Windows\\system32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages']
Server time:    Thu, 10 Aug 2017 11:41:38 +0000
Run Code Online (Sandbox Code Playgroud)

但我class MetaUserSerializer课堂上有"serializers.py"文件,请看看并给我一个帮助. …

python django rest

3
推荐指数
2
解决办法
4187
查看次数

Angular2,调用服务函数,无法读取未定义的属性'***'

我从服务中调用函数,但我总是得到Cannot read property 'getCurrentUser' of undefined.

这是我的服务, authentication.service.ts

import { Injectable } from '@angular/core';
import { Http, Headers, Response, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';

@Injectable()
export class AuthenticationService {
  public token: string;
  private url = 'http://192.168.201.211:8024/api-token-auth/';
  private options: RequestOptions;
  private currentUser: any;

  constructor(private http: Http) {
    // set token if saved in local storage
    this.currentUser = JSON.parse(localStorage.getItem('currentUser'));
    this.token = this.currentUser && this.currentUser.token;
    let headers = new Headers({ 'Content-Type': 'application/json' });
    this.options …
Run Code Online (Sandbox Code Playgroud)

typescript angular

3
推荐指数
1
解决办法
4313
查看次数

django无法在docker-compose中连接mysql

我是docker的新手,现在我试图通过docker-compose在docker中使用mariadb运行django,但我总是遇到这个错误:

我用Docker version 17.09.1-ce, build 19e2cf6,docker-compose version 1.18.0, build 8dd22a9

django.db.utils.OperationalError:(2003年,'无法连接到'mariadb55上的MySQL服务器'(111"连接被拒绝")')

我可以docker-compose up db在本地或远程运行后正确连接数据库,我甚至可以python manage.py runserver 0.0.0.0:6001anaconda虚拟环境中正确运行db,通过设置settings.py文件的参数来连接docker中的服务,如下所示:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'test',
        'USER': 'belter',
        # 'HOST': 'mariadb55',
        'HOST': '127.0.0.1',
        'PORT': '3302',
        'PASSWORD': 'belter_2017',
        'default-character-set': 'utf8',
        'OPTIONS': {
            'sql_mode': 'traditional',
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的docker-compose.yml文件

version: '3'

services:
  db:
    image: mariadb:5.5
    restart: always
    environment:
      - MYSQL_HOST=localhost
      - MYSQL_PORT=3306
      - MYSQL_ROOT_HOST=%
      - MYSQL_DATABASE=test
      - …
Run Code Online (Sandbox Code Playgroud)

mysql django mariadb docker docker-compose

2
推荐指数
1
解决办法
5722
查看次数

Django 1.10自定义用户'is_superuser'与模型中的字段'is_superuser'相冲突

我写了一个自定义的用户类- CustomUsermodels.py,主要遵循这里

import re

from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail
from django.core import validators
from django.contrib.auth.models import (AbstractUser, PermissionsMixin,
                                        UserManager)


class CustomUser(AbstractUser, PermissionsMixin):
    """
    custom user, reference below example
    https://github.com/jonathanchu/django-custom-user-example/blob/master/customuser/accounts/models.py
    """
    username = models.CharField(_('username'), max_length=30, unique=True,
                                help_text=_('Required. 30 characters or fewer. Letters, numbers and '
                                            '@/./+/-/_ characters'),
                                validators=[validators.RegexValidator(
                                    re.compile('^[\w.@+-]+$'), _('Enter a valid username.'), 'invalid')
    ])
    email = models.EmailField(_('email address'), max_length=254)
    create_time = models.DateTimeField(auto_now_add=True)
    active …
Run Code Online (Sandbox Code Playgroud)

django django-models

1
推荐指数
1
解决办法
1577
查看次数