我想在视图中创建密码作为密码字段.请有人帮帮我吗?提前致谢
class User(models.Model):
username = models.CharField(max_length=100)
password = models.CharField(max_length=50)
Run Code Online (Sandbox Code Playgroud) 我正在编写一个单元测试来检查电子邮件验证逻辑.运行测试时,逻辑是抛出空指针异常.但它适用于模拟器.有人可以帮我解决这个问题吗?
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) 我正在构建一个多人游戏,所以一旦服务器启动我想连续广播服务器名称,以便客户端可以知道有一些服务器正在运行.我不想给IP地址和端口号连接到服务器.有人可以帮我广播服务器名称.
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)
我正在尝试将组合框添加到框架中。但它是不可见的。如果您单击该位置,它将显示选项。但它是不可见的。如果我遗漏了一些内容,请告诉我。
如果我打印request.POST.username和request.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) 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) 有没有可以用来将 cron 表达式转换为时间间隔的 java 库?可以是秒、毫秒、分钟等......
Cron Expression (Input): 0/15 * * * * ?
Output1: 15 (getInSeconds)
Output2: 15000 (getInMilliSeconds)
Run Code Online (Sandbox Code Playgroud) java ×3
python ×3
android ×2
django ×2
django-forms ×2
cron-task ×1
crontrigger ×1
django-views ×1
junit ×1
junit4 ×1
python-2.7 ×1
sockets ×1
socketserver ×1
swing ×1