django:无法从其他.py创建对象(模型sqlite3)

时间:2022-01-15 04:14:19

I use Django. I've created a project and an app.

我用Django。我创建了一个项目和一个应用程序。

views.py

..
import xmlparser
from models import Actividad
..
def All(request):
    xmlparser.MyHandler.procesar
    return HttpResponse("test")

xmlparser, xml sax parser, it works and prints content working out of django

xmlparser,xml sax解析器,它工作并打印django工作的内容

from models import Actividad
..
class MyHandler

def characters (self, content):
    A = Actividad.objects.create(titulo = "..", tipo = "..")

def procesar (self):
    parser = xml.sax.make_parser()
    parser.setFeature(xml.sax.handler.feature_namespaces, 0)

    Handler = MyHandler()
    parser.setContentHandler(Handler)
    parser.parse('your.xml')

A has not been added when I go to "All" url. If I try, with the same line, to add info to the db from views.py, it works.

当我转到“全部”网址时,尚未添加A.如果我尝试使用相同的行,从views.py向db添加信息,它可以工作。

1 个解决方案

#1


0  

This line :

这一行:

xmlparser.MyHandler.procesar

doesn't actually call your method. It needs the parens:

实际上并没有调用你的方法。它需要parens:

xmlparser.MyHandler.procesar()

#1


0  

This line :

这一行:

xmlparser.MyHandler.procesar

doesn't actually call your method. It needs the parens:

实际上并没有调用你的方法。它需要parens:

xmlparser.MyHandler.procesar()