我在我的model.py中得到一个SyntaxError,这可能是我的代码的问题

时间:2017-08-11 12:29:38

标签: django python-2.7 fedora-25

我在model.py中写了我的代码,但是我在开发服务器中遇到了这个错误。欢迎提出任何建议。我已经在stackflow中遵循了之前的建议,但我无法得到解决我的代码的任何答案。 错误:下面的代码是我得到的错误。

 Unhandled exception in thread started by <function wrapper at 0x7fe6d63e4938>
    Traceback (most recent call last):
      File "/usr/lib64/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper
        fn(*args, **kwargs)
      File "/usr/lib64/python2.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
        autoreload.raise_last_exception()
      File "/usr/lib64/python2.7/site-packages/django/utils/autoreload.py", line 250, in raise_last_exception
        six.reraise(*_exception)
      File "/usr/lib64/python2.7/site-packages/django/utils/autoreload.py", line 227, in wrapper
        fn(*args, **kwargs)
      File "/usr/lib64/python2.7/site-packages/django/__init__.py", line 27, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 108, in populate
        app_config.import_models()
      File "/usr/lib64/python2.7/site-packages/django/apps/config.py", line 202, in import_models
        self.models_module = import_module(models_module_name)
      File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
      File "/home/harrugg2/projects/django/church/tithe/models.py", line 24
        def print(self):
                ^
    SyntaxError: invalid syntax

下面是我的model.py

代码
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.utils import timezone
from django.db import models

# Create your models here.
class tithe(models.models):
    genarationNo = models(ForeignKey('generationNo.User'))
    memberid = models.IntField()
    membername = models.VacharField()
    tithe = models.IntField()
    combinedoffering = models.IntField(max_length=45)
    campmeetingoffering = models.IntField(IntField=45)
    churchbuilding = models.IntField(max_length=45)
    conference = models.IntField(max_length=45)
    localchurch = models.IntField(max_length=45)
    funds = models.IntField(max_length=45)
    total = models.IntField(max_length=45)
    created_date = models.DateTimeField(
            default=timezone.now)
    printed_date = models.DateTimeField(
            blank=True, null=True)

    def print(self):
        self.printed_date = timezone.now()
        self.save()

    def __str__(self):
        return self.generationNo

    class Meta:
        unique_together = ["generationNo","IntField"]
        ordering = ["printed_date","membername"]

2 个答案:

答案 0 :(得分:3)

print是该语言的关键字。它是保留的,不能用作标识符。 See this

答案 1 :(得分:1)

正如其他人所说,print对于函数来说不是一个好名字,但是你的代码还有其他一些奇怪之处。 在unique_together中,您引用的是不存在的字段。