简体   繁体   中英

Django Model not Defined in views.py

I have a django app that I'm trying to provide an ID and have it return records from a mysql database based on that ID.

Here's my models.py:

from django.db import models

class RateskioskMain(models.Model):
    EID = models.BigIntegerField(unique=True, default=0,)
    ETISmUnits = models.BigIntegerField(blank=True, default=0)
    ETISmHours = models.FloatField(blank=True, default=0)

It created a table in my database called rateskiosk_rateskioskmain.

Here's my views.py:

def homepage_view(request):
    result_obj = None
    if request.method == 'GET':
        pass
    elif request.method == 'POST':
        eid = request.POST.get('eid')
        result_count = RateskioskMain.objects.filter(EID=int(eid)).count()
        if result_count > 0:
            result_obj = RateskioskMain.objects.get(EID=eid)
    return render(request, 'ratekiosk/homepage.html', {'result_obj': result_obj})

But then when I try to run it, I get:

Exception Type: NameError at /
Exception Value: name 'RakesKioskMain' is not defined

Not sure what I'm missing, but any help is greatly appreciated.

You have to import RakesKioskMain into your views.py. Do:

from *App*.models import RakesKiosMain

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM