将原始html数据保存到postgresql数据库

时间:2019-12-13 08:07:18

标签: python django postgresql

任何人都可以帮助我解决此问题。我想将原始HTML数据保存到Django PostgreSQL数据库。我目前对Django和编程都不熟悉,我已经花了很多时间并且仍然可以解决它。任何帮助将不胜感激。

我的错误

这是我在网络浏览器中看到的错误。

NameError at /
name 'models' is not defined
Request Method: POST
Request URL:    http://127.0.0.1:8000/
Django Version: 2.2.8
Exception Type: NameError
Exception Value:    
name 'models' is not defined
Exception Location: D:\Django\TimeSheetProject\morabu_timesheet\views.py in create_timesheet_view, line 18
Python Executable:  D:\Django\TimeSheetProject\morabu\Scripts\python.exe
Python Version: 3.7.2
Python Path:    
['D:\\Django\\TimeSheetProject',
 'D:\\Django\\TimeSheetProject\\morabu\\Scripts\\python37.zip',
 'D:\\Django\\TimeSheetProject\\morabu\\DLLs',
 'D:\\Django\\TimeSheetProject\\morabu\\lib',
 'D:\\Django\\TimeSheetProject\\morabu\\Scripts',
 'c:\\program files\\python\\Lib',
 'c:\\program files\\python\\DLLs',
 'D:\\Django\\TimeSheetProject\\morabu',
 'D:\\Django\\TimeSheetProject\\morabu\\lib\\site-packages']
Server time:    Fri, 13 Dec 2019 16:55:22 +0900

这是我创建的models.py文件。

from django.db import models

# Create your models here.
class TimesheetDetails(models.Model):
    date = models.CharField(max_length = 10)
    day = models.CharField(max_length = 10)
    startTime = models.CharField(max_length =10)
    endTime = models.CharField(max_length =10)
    breakTime = models.CharField(max_length=3)
    normalTime = models.CharField(max_length=10)
    overTime = models.CharField(max_length = 10)
    holidayTime = models.CharField(max_length = 10)
    weekType = models.CharField( max_length = 10)
    attendance = models.CharField( max_length = 10)
    content = models.TextField( max_length = 10)

我的views.py代码

from . models import TimesheetDetails

# Create your views here.
def create_timesheet_view(request):
    getDate = request.POST.get('date_today');
    getDay = request.POST.get('day_today');
    getStartTime = request.POST.get('startTime');
    getEndTime = request.POST.get('endTime');
    getBreakTime = request.POST.get('breakTime');
    getNormalTime = request.POST.get('normalTime');
    getOverTime = request.POST.get('overTime');
    getHolidayTime = request.POST.get('holidayTime');
    getWeekType = request.POST.get('weekType');
    getAttendance = request.POST.get('attendance');
    getContent = request.POST.get('content');

    formData = TimesheetDetails(date=getDate,day=getDay,startTime=getStartTime,
                                endTime=getEndTime,breakTime=getBreakTime,normalTime=getNormalTime,
                                overTime=getOverTime,holidayTime=getHolidayTime,weekType=getWeekType,
                                attendance=getAttendance,content=getContent)
    formData.save()
    return render(request,"timesheet/create_timesheet.html")

我的HTML表单

<form action="" method="post" autocomplete="off">
        {% csrf_token %}  
        <h3 id="date_Today"></h3> <p class="hideElement" id="date_today"name="date_today"></p><p class="hideElement"id="dayToday"name="dayToday"></p>
        <div class="row">
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="startTime">開始時間</label>
                    <input type="text" class="form-control" name="startTime" id="startTime" placeholder="(HH:mm)フォーマットに入力して下さい">
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="endTime">終業時間</label>
                    <input type="text" class="form-control" name="endTime" id="endTime" placeholder="(HH:mm)フォーマットに入力して下さい">
                </div>
            </div>
            <div class="col-sm-4">
                <div class="form-group">
                    <label for="breakTime">休憩時間</label>
                    <input type="text" class="form-control" name="breakTime" id="breakTime" >
                </div>
            </div>
        </div> 

        <div class="row">
                <div class="col-sm-4">
                    <div class="form-group">
                        <label for="normalTime">時間内時間</label>
                        <input type="text" class="form-control" name="breakTime" id="normalTime" >
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="form-group">
                        <label for="extraTime">時間外時間</label>
                        <input type="text" class="form-control" name="extraTime" id="extraTime">
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="form-group">
                        <label for="holidayTime">休日時間</label>
                        <input type="text" class="form-control" name="holidayTime" id="holidayTime" >
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label for="weekType">区分は間違えないでしょうか?</label>
                        <select class="form-control" name="weekType" id="weekType">
                            <option value="平日">平日</option>
                            <option value="休日">休日</option>
                        </select>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group">
                        <label for="reason">勤怠を選んでください!</label>
                        <select class="form-control" name="attendance" id="attendance">
                            <option value="欠勤">欠勤</option>
                            <option value="有給休暇">有給休暇</option>
                            <option value="振替休日">振替休日</option>
                            <option value="特別休暇">特別休暇</option>
                            <option value="残業">残業</option>
                            <option value="早退">早退</option>
                            <option value="遅刻">遅刻</option>
                            <option value="直行">直行</option>
                            <option value="直帰">直帰</option>
                            <option value="その他">その他</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label for="workContent">恐れ入りますが、仕事の内容を書いていただきませんでしょうか?</label>
                        <textarea class="form-control" name="workContent" id="workContent" rows="3"></textarea>
                    </div>
                </div>
            </div>       
        </div>
        <button type="submit" class="btn btn-success btn-block"><i class="fas fa-database"></i> 保存</button>

    </form>
</div>

0 个答案:

没有答案