小编Hem*_*S R的帖子

如何在模型django中创建密码字段

我想在视图中创建密码作为密码字段.请有人帮帮我吗?提前致谢

class User(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=50)
Run Code Online (Sandbox Code Playgroud)

python django django-models django-forms

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

验证电子邮件时出现NullPointerException

我正在编写一个单元测试来检查电子邮件验证逻辑.运行测试时,逻辑是抛出空指针异常.但它适用于模拟器.有人可以帮我解决这个问题吗?

public static String validate(String email, String password) {
        if (email == null || email.isEmpty() || !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
            return "Enter valid email address";
        }
        if (password.isEmpty() || password.length() < 4) {
            return "Password should be between 4 and 10 alphanumeric characters";
        }
        return null;
}
Run Code Online (Sandbox Code Playgroud)

以下是我的单元测试.

@Test
public void validateShouldReturnMessageIfYouPassAnInvalidEmail() throws Exception {
    String validateMessage = LoginService.validate("abcdef", "password");
    assertEquals("Enter valid email address", validateMessage);
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是,

java.lang.NullPointerException
at com.tryout.hemanth.expensetracker.service.LoginService.validate(LoginService.java:11)
Run Code Online (Sandbox Code Playgroud)

java junit android junit4 android-studio

5
推荐指数
2
解决办法
1214
查看次数

在python中广播套接字服务器

我正在构建一个多人游戏,所以一旦服务器启动我想连续广播服务器名称,以便客户端可以知道有一些服务器正在运行.我不想给IP地址和端口号连接到服务器.有人可以帮我广播服务器名称.

  • 它的应用程序不是Web应用程序.

python sockets socketserver python-2.7 python-sockets

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

为什么 jcombobox 不可见?

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class Dummy{
    String newSelection = null;

    public void init(){
        JFrame jFrame = new JFrame("Something");
        jFrame.setVisible(true);
        jFrame.setSize(new Dimension(600, 600));
        jFrame.setLayout(null);
        jFrame.setBackground(Color.BLACK);

        final String[] possibleNoOfPlayers = {"Two","Three"};

        final JComboBox comboBox = new JComboBox(possibleNoOfPlayers);
        newSelection = possibleNoOfPlayers[0];
        comboBox.setPreferredSize(new Dimension(200,130));
        comboBox.setLocation(new Point(200,200));
        comboBox.setEditable(true);
        comboBox.setSelectedIndex(0);
        comboBox.setVisible(true);
        comboBox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                JComboBox box = (JComboBox) actionEvent.getSource();
                newSelection = (String) box.getSelectedItem();
                System.out.println(newSelection);
            }
        });
        jFrame.add(comboBox);
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试将组合框添加到框架中。但它是不可见的。如果您单击该位置,它将显示选项。但它是不可见的。如果我遗漏了一些内容,请告诉我。

java swing

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

表单对象在django中没有属性'isValid'

如果我打印request.POST.usernamerequest.POST.password,我得到正确的数据.但我无法验证表格.我无法得到cleaned_data.

views.py

def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.isValid():
            print "coming"
        return render_to_response('html/index.html')
    else:
        form = LoginForm()
        c = {'logInForm': form, }
        return render_to_response('html/index.html', c, RequestContext(request))
Run Code Online (Sandbox Code Playgroud)

forms.py

from django import forms
class LoginForm(forms.Form):
    username = forms.EmailField()
    password = forms.CharField(max_length=50)
Run Code Online (Sandbox Code Playgroud)

的index.html

<!DOCTYPE html>
<html>
<head>
    .....
</head>
<body>

<div class="container">

    <form class="form-signin" action="login" method="post">{% csrf_token %}
        {{ logInForm.as_p }}
        <input type="submit" value="Submit"/>
    </form>
</div> 
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

python django django-templates django-forms django-views

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

如何在android中动态地将字符串添加到ListView?

public class MyActivity extends Activity {
    Context context;
    List<String> tasks;
    ArrayAdapter<String> adapter;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        context = this;
        tasks = new ArrayList<String>();

        Button add = (Button) findViewById(R.id.button);
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EditText editText = (EditText) findViewById(R.id.editText);
                editText.setVisibility(1);

                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(editText, 0);

                String value = editText.getText().toString();
                tasks.add(value);

                adapter = new ArrayAdapter<String>(context,R.id.listView,tasks);
                ListView listView = (ListView) findViewById(R.id.listView);
                listView.setAdapter(adapter);
            } …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-listview

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

有没有java库可以将cron表达式转换为间隔?

有没有可以用来将 cron 表达式转换为时间间隔的 java 库?可以是秒、毫秒、分钟等......

Cron Expression (Input): 0/15 * * * * ?

Output1: 15 (getInSeconds)
Output2: 15000 (getInMilliSeconds)
Run Code Online (Sandbox Code Playgroud)

java quartz-scheduler crontrigger cron-task cronexpression

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