社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Django

输入日期值属性django

TOLULOPE ADETULA • 7 年前 • 1884 次点击  

我试图在HTML中显示数据库中日期字段的值,但该字段仍然显示空白文本

我试过在设置日期值时使用Django管道。当我在标签中使用相同的代码时,它工作得很好,但不只是在日期字段中工作

这是my views.py文件

def all(request):
    employees = Employee.objects.all().order_by('last_name')
    departments = Department.objects.all()
    table = EmployeeTable(employees)
    RequestConfig(request).configure(table)
    context =  {
        'table':table,
        'employees':employees,
        'departments':departments
    }
    if request.method == "POST":
        first_name = request.POST['first_name']
        last_name = request.POST['last_name']
        name = last_name +' '+first_name
        employee_id = request.POST['employee_id']
        email = request.POST['email']
        department = Department.objects.get(dept_name = request.POST['department'])
        address = request.POST['address']
        employment_type = request.POST['employment_type']
        employment_status = request.POST['employment_status']
        role = request.POST['role']
        marital_status = request.POST['marital_status']
        gender = request.POST['gender']
        join_date = request.POST['join_date']
        end_date = None if len(request.POST['end_date']) ==0 else request.POST['end_date']
        location = request.POST['location']
        credentials = request.POST['credentials']
        passport = request.POST['passport']
        hod = request.POST['hod']
        phone_number = request.POST['phone_number']
        date_of_birth = request.POST['date_of_birth']
        date_added = datetime.now()

这是我的HTML代码

<div class="col-sm-6">
  <div class="form-group">
     <label for='date_of_birth' class="control-label">Date of Birth
       {{employee.date_of_birth|date:'Y/m/d'}}  
       {{employee.date_of_birth|date:'m-d-Y'}}  
       {{employee.date_of_birth|date:'SHORT_DATE_FORMAT'}} <span class="text- 
       danger">*</span>
     </label>
     <input name='date_of_birth' type="date"  class="form-control" value = " 
     {{employee.date_of_birth|date:'m/d/Y'}} " >
   </div>
</div>

Result

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/49669
文章 [ 1 ]  |  最新文章 7 年前