Django-模型类django_otp.plugins.otp_static.models.StaticDevice没有声明显式的app_label

时间:2019-03-17 12:11:13

标签: python django

我正在尝试使用this library。当我使用from allauth_2fa import views在自己的 urls.py 中导入视图时,出现以下错误:

   File "C:\Users\User\Desktop\Heroku\github\backup\main\urls.py", line 20, in <module>
    from allauth_2fa import views
  File "C:\Users\User\lib\site-packages\allauth_2fa\views.py", line 23, in <module>
    from django_otp.plugins.otp_static.models import StaticToken
  File "C:\Users\User\lib\site-packages\django_otp\plugins\otp_static\models.py", line 11, in <module>
    class StaticDevice(Device):
  File "C:\Users\User\lib\site-packages\django\db\models\base.py", line 95, in __new__
    "INSTALLED_APPS." % (module, name)
RuntimeError: Model class django_otp.plugins.otp_static.models.StaticDevice doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

我不知道我做错了什么,还是该错误在依赖模块中。谁能帮我吗?

1 个答案:

答案 0 :(得分:1)

我认为您错过了一些流程。您没有在INSTALLED_APPS中添加import React from "react"; import {StyleSheet, View, Button, Text, FlatList, TextInput, ListView} from "react-native"; import firebase from './firebase' let db = firebase.firestore(); class TextInputExample extends React.Component { constructor(props) { super(props); this.state = { data: [], userName: '', userAge: '', input1Background: 'red', textColor1: 'white', input2Background: 'red', textColor2: 'white' }; } componentDidMount(): void { db.collection('users') .onSnapshot((snapshot) => { snapshot.docChanges().forEach(change => { if (change.type === 'added') { this.state.data.push({ name: change.doc.get('name'), age: change.doc.get('age') }); console.log(this.state.data); } }) }, (error => { console.log(error.message); })) } addToDatabase = () => { let data = { name: this.state.userName, age: this.state.userAge }; console.log(data); db.collection('users').add(data) .then(ref => { }).catch(msg => { console.log(msg); }); }; renderItem = ({item}) => { return( <View> <Text>{item.name}</Text> <Text>{item.age}</Text> </View> ); }; render(): React.Node { return ( <View style={styles.container}> <TextInput placeHolder={'Enter name'} onChangeText={(text) => this.setState( {userName: text} )} /> <TextInput placeHolder={'Enter Age'} onChangeText={(text) => this.setState( {userAge: text} )} /> <Button title={'Add'} onPress={() => this.addToDatabase()}/> <View> <FlatList data={this.state.data} renderItem={this.renderItem} /> </View> </View> ); } } export default TextInputExample; const styles = StyleSheet.create({ container: { flex: 1, alignSelf: 'center', alignItems: 'center' } });,也没有迁移它。我尝试将其配置写完整的过程。

第1步:

allauth_2fa

第2步:

应用settings.py文件中的那些

pip install django-allauth-2fa

第3步:

INSTALLED_APPS = (
    # Required by allauth.
    'django.contrib.sites',

    # Configure Django auth package.
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',

    # Enable allauth.
    'allauth',
    'allauth.account',

    # Configure the django-otp package.
    'django_otp',
    'django_otp.plugins.otp_totp',
    'django_otp.plugins.otp_static',

    # Enable two-factor auth.
    'allauth_2fa',
)

第4步:

MIDDLEWARE_CLASSES = (
    # Configure Django auth package.
    'django.contrib.auth.middleware.AuthenticationMiddleware',

    # Configure the django-otp package. Note this must be after the
    # AuthenticationMiddleware.
    'django_otp.middleware.OTPMiddleware',

    # Reset login flow middleware. If this middleware is included, the login
    # flow is reset if another page is loaded between login and successfully
    # entering two-factor credentials.
    'allauth_2fa.middleware.AllauthTwoFactorMiddleware',
)
# Set the allauth adapter to be the 2FA adapter.
ACCOUNT_ADAPTER = 'allauth_2fa.adapter.OTPAdapter'

第5步:

现在您可以将其导入到视图文件中 还必须在urls.py文件中配置

如果在下面遇到任何问题评论