小编cha*_*ate的帖子

Django自定义登录页面

我有一个自定义的Django登录页面.我想在用户名或密码字段为空时抛出异常.我怎样才能做到这一点?

我的view.py登录方法:

def user_login(request):
    context = RequestContext(request)
    if request.method == 'POST':
        # Gather the username and password provided by the user.
        # This information is obtained from the login form.
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        print("auth",str(authenticate(username=username, password=password)))

        if user:
            # Is the account active? It could have been disabled.
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect('/')
        else:
            return HttpResponse("xxx.")
    else:
        # Bad login details were provided. So we can't log the user in.
        print ("Invalid login …
Run Code Online (Sandbox Code Playgroud)

python django validation login

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

所有卡的TextField值更改

我正在制作体育馆日记,每步动作都有“卡片”,其中包括“ setsreps kg”。因此,代码在视图中生成了尽可能多的卡“ Squat”和“ Front-squat”。这里的问题是我在两张卡中都使用controllerSets。如果我将“下蹲”设置编号更改为“ 2”,则“前蹲”设置编号也更改为“ 2”,因为它使用相同的controllerSets TextEditingController。这是我的问题,请考虑甚至可以有10个移动,我不希望为每个移动创建10 x 3控制器。我的问题是我应该如何构建此功能?完整的代码可以在这里找到:

return Column(
  children: <Widget>[
    Text(
      _programMovesGen(program)[index],
      textAlign: TextAlign.center,
      style: TextStyle().copyWith(color: Colors.black, fontSize: 18.0),
    ), // Move name
    Row(
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: <Widget>[
        new Flexible(
          child: Padding(
            padding: const EdgeInsets.all(18.0),
            child: new TextFormField(
                controller: controllerSets,
                keyboardType: TextInputType.number,
                inputFormatters: [
                  LengthLimitingTextInputFormatter(2),
                ]),
          ),
        ),
        Text(
          "sets ",
          textAlign: TextAlign.center,
          style: TextStyle().copyWith(color: Colors.black, fontSize: 18.0),
        ),
        new Flexible(
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: new TextFormField(
                controller: controllerReps,
                keyboardType: TextInputType.number,
                inputFormatters: …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

Firebase根据日期按点排序

我想添加一个月度记分牌,但对我来说似乎有点困难.我不知道如何将特定值取为某个列表或数组.与日期一样,只有09.01.2017值的日期.如果我能做到那么我认为我可以按价值对它们进行排序.

在此输入图像描述

        FirebaseDatabase database = FirebaseDatabase.getInstance();
    final DatabaseReference highscoreRef = database.getReference();




    // Ordering with score and adding key values as string to nameList and scoreList
    highscoreRef.orderByChild("score").limitToLast(10).addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot snapshot, String previousChildKey) {
            try {

                nameList.push(snapshot.child("name").getValue().toString());
                scoreList.push(snapshot.child("score").getValue().toString());

            } catch (Exception e) {
                //Toast.makeText(getApplicationContext(), "Error fetching data.", Toast.LENGTH_SHORT).show();
            }
        }
        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }
        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }
        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }
        @Override
        public void onCancelled(DatabaseError …
Run Code Online (Sandbox Code Playgroud)

sorting android firebase firebase-realtime-database

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

反应原生的每一行的renderRow索引

我试图获取renderRow的当前索引,但我似乎没有得到它.我还尝试将i作为变量添加到renderRow中.我正在制作高分,如果我可以从renderRow本身获取数字,那将是非常方便的.如果每次都有另一种获取当前数字的方法,那么它也会起作用.

          <ListView
          dataSource={this.state.dataSource}
          renderRow={(rowData, rowID ) =>
          <Text style={styles.topStyle}>{rowID}</Text>
          }
      />
Run Code Online (Sandbox Code Playgroud)

scripting android reactjs react-native

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

2 Int的元组和Unity C#中的contains方法

尝试制作两个Integer的列表元组,然后在其中添加一些内容。然后比较x,y是否为列表元组中的元组之一。

List<Tuple<int, int>> monsterPositions;
Run Code Online (Sandbox Code Playgroud)

我立即收到这样的错误,它没有Tuple:

Assets / TimeMap.cs(20,7):错误CS0246:找不到类型或名称空间名称“元组”。您是否缺少装配参考?

我发现我可以像这样添加内部元组:

monsterPositions.Add(randomX, randomY);
Run Code Online (Sandbox Code Playgroud)

然后最困难的部分是如何比较元组列表中的x和y。我正在尝试使用,Contains但我不知道这有什么问题。

monsterPositions.Contains(Tuple(x, y));
Run Code Online (Sandbox Code Playgroud)

c# tuples unity-game-engine

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

Django 在 javascript 中调用 url

我正在做我的 django 项目,但我找不到如何从 javascript 函数调用我的网站的答案。

  var time = 5;
  setInterval(function() {
    if(time > 0) {
      document.getElementById("timecounter").innerHTML = "You will be redirected in "
      + time + " seconds. If not then ";
      time--;
    } else {
      location.href="{% url 'index' %}"
    }

  },1000)
Run Code Online (Sandbox Code Playgroud)

这个 location.href 重定向到错误的地方。它的字面意思是将“{% url 'index' %}”放在 URL 中。

谢谢你的帮助!

javascript django redirect django-templates url-redirection

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

Flutter:如何将变量从 StatelessWidget 传递到 StatefulWidget

问题是我无法将我自己的类 ForceSelection 值从另一个屏幕传递到另一个屏幕的 StatefulWidget。它在 StatelessWidget 中运行良好。我试图从这个颤振教程中学习:https : //flutter.dev/docs/cookbook/navigation/passing-data#4-navigate-and-pass-data-to-the-detail-screen

我在 levelSelection.dart 中有这种类

class ForceSelection {
  final String forceSelection;
  final String langSelection;

  ForceSelection(this.forceSelection, this.langSelection);
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试将值传递给下一个文件 PlayQuiz.dart

Game(forceSelection: ForceSelection('maa', 'fin'))
Run Code Online (Sandbox Code Playgroud)

game.dart 看起来像这样:

class Game extends StatelessWidget {
  final ForceSelection forceSelection;

  Game({Key key, @required this.forceSelection}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: forceSelection.langSelection, // TODO should work and change later
      theme: new ThemeData(
        primaryColor: Colors.white,
      ),
      home: PlayQuiz(),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

我想将 ForceSelection 值传递给 PlayQuiz()

class PlayQuizState extends …
Run Code Online (Sandbox Code Playgroud)

android dart flutter

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