我正在尝试使用 DateInput,但Required argument 'year' (pos 1) not found在此处出现以下错误
{{ form.incident_date_time_reported|add_class:"form-control"}}(第 52 行)
表格.py
from django import forms
import datetime
from functools import partial
DateInput = partial(forms.DateInput, {'class': 'datepicker'})
class IncidentForm(forms.Form):
incident_date_time_reported = forms.DateField(initial=datetime.date, required=False, widget=forms.DateInput)
def search(self):
# cleaning the data
incident_date_time_reported = self.cleaned_data.get('incident_date_time_reported')
query = Incident.objects.all()
if incident_date_time_reported is not None:
query = query.filter(incident_date_time_reported=incident_date_time_reported)
return(query)
Run Code Online (Sandbox Code Playgroud)
索引.html
{% extends "base.html" %}
{% load widget_tweaks %}
{% block content %}
<div class="container-fluid">
<!-----INPUT FORM------------------->
<form action="{% url 'incidents:index' …Run Code Online (Sandbox Code Playgroud) class CapaForm(forms.Form):
capa = forms.CharField(required=False)
Run Code Online (Sandbox Code Playgroud)
提交表单后,我想检查capa字段的格式.我想要求用户正确输入capa格式为6个数字,短划线和两个数字.(###### - ##)
def search(self):
capa = self.cleaned_data.get('capa', None)
if ("\d{6}\-\d{2}" or None) not in capa:
raise forms.ValidationError("CAPA format needs to be ######-##!")
Run Code Online (Sandbox Code Playgroud)
它目前不允许我提交格式正确的capa并抛出ValidationError.我认为问题是我正在尝试将正则表达式与对象进行比较.如何检查用户尝试提交的'capa'的格式?
*********UPDATE
当我在CAPA字段中输入错误的格式时,现在一切正常.我收到错误The view incidents.views.index didn't return an HttpResponse object. It returned None instead.这与我所做的更改有关吗?
from django.core.validators import RegexValidator
my_validator = RegexValidator("\d{6}\-\d{2}", "CAPA format needs to be ######-##.")
class CapaForm(forms.Form):
capa = forms.CharField(
label="CAPA",
required=False, # Note: validators are not run against empty fields
validators=[my_validator]
)
def search(self):
capa …Run Code Online (Sandbox Code Playgroud) 我无法弄清楚shell /usr/bin/virtualenvwrapper.sh在服务器登录时尝试运行的位置.我希望virtualenvwrapper永久卸载,而不仅仅是从shell实例中删除.我以为我卸载了它pip uninstall virtualenvwrapper,但每次登录服务器时我都会收到错误-bash: /usr/bin/virtualenvwrapper.sh: No such file or directory,好像有一些剩余的工件.昨天我做了很多修修补补,我记不起所做的所有改变或者我是如何做到这一点的.它在哪里执行搜索virtualenvwrapper.sh?
补充信息
$ echo $PATH
/usr/lib64/qt-3.3/bin
/usr/local/bin/ibm/lsf/9.1/linux2.6-glibc2.3-x86_64/etc
/usr/local/bin/ibm/lsf/9.1/linux2.6-glibc2.3-x86_64/bin
/usr/local/bin
/bin
/usr/bin
/usr/local/sbin
/usr/sbin
/sbin/usr/local/bin/CASAVA-1.8.2/bin
/usr/local/bin/blast
/usr/local/bin/mirdeep2
/usr/local/bin/velvet
$ sudo vim ~/.bashrc
1 # .bashrc
2
3 # Source global definitions
4 if [ -f /etc/bashrc ]; then
5 . /etc/bashrc
6 fi
7
8 # User specific aliases and functions
Run Code Online (Sandbox Code Playgroud) 我正在创建自定义身份验证登录.除了在电子邮件和密码不正确时显示错误消息外,一切似乎都有效.
我知道这与登录失败时我对login.html页面的呈现有关,而且没有提供表单,因为尝试登录失败这一事实,但我不知道如何将其放入我的代码.
views.py
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponseRedirect
def login_user(request):
logout(request) #logs out user upon reaching the /login/ page
email = password = ''
if request.POST:
email = request.POST['email']
password = request.POST['password']
user = authenticate(email=email, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect('/successful_login/')
else:
state = "Your account is not active, please contact the administrator." …Run Code Online (Sandbox Code Playgroud) 我正在尝试在forms.py中动态创建查询.我将它存储为字符串,然后尝试过滤并返回它,但我收到错误...
filter() argument after ** must be a mapping, not str
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?显然它不喜欢它.它应该是不同的数据类型吗?
forms.py
from django import forms
from django.db.models import Q
from .models import Incident
from .models import Equipment
class IncidentForm(forms.Form):
incident_id = forms.IntegerField(required=False)
equipment_id = forms.ModelChoiceField(Equipment.objects.all(), required=False, widget=forms.TextInput)
def search(self):
# cleaning the data
cust_id = self.cleaned_data.get('incident_id')
equip_id = self.cleaned_data.get('equipment_id')
user_input = [cust_id, equip_id]
# finding blank fields
i = 0
lst=[]
for x in user_input:
if x != None:
lst.append(i)
i += 1
# setting up query with …Run Code Online (Sandbox Code Playgroud) 用[3]数值对Hash of Arrays进行排序的最简单方法是什么?
例如......我想从最大值到最小值对值为6125,1686,700的散列进行排序.我最初虽然把这些值作为键,但其中一些数字在其他数组中是相同的.
'12' => [
'+',
'ATGGTTTTCTTCTCTCCTTCCCTCTCCAGCCTGCTGTATAAGTAA',
'MGLGLAPSWPSLLTSSYPECVPYLFSHLLPPTTQPYPFSPSLSSLLYK*',
6125
],
'41' => [
'+',
'ATGGGAGTTTACTGTGATGACTTGAGGACAGAGGGACTCTAG',
'MGVYCDDLRTEGL*',
1686
],
'16' => [
'+',
'ATGGGAGTTTACTGTGATGACTTGAGGACAGAGGGACTCTAG',
'MGVYCDDLRTEGL*',
700
]
Run Code Online (Sandbox Code Playgroud) django ×4
django-forms ×2
forms ×2
python ×2
bash ×1
datefield ×1
linux ×1
perl ×1
python-3.x ×1
regex ×1
shell ×1
sorting ×1
validation ×1