Python Django Shell Debugging

Source: Internet
Author: User

Python Django Debugging

>>> class person (models. Model): ...     First_Name = models. Charfield (max_length = ...)     Last_Name = models. Charfield (max_length = ...)     def __unicode__ (self): ...         return u '%s '% (Self.first_name, self.last_name) ... Traceback (most recent): File "<console>", line 1, in <module>file "/usr/lib/python2.7/ site-packages/django/db/models/base.py ", line 117, in __new__    Kwargs = {" App_label ": Package_components[app_label _index]}indexerror:list index out of range

The definition of the model must be in the application-you see there it tries to take the name model_module Error-This should have some like for project\appname\ Models.py-project.appname.models, and get the name of the application, appname come. The module name is 'main' in the interactive console, so it will fail.

In order to solve this problem, you need to specify the App_label in the Meta class,

>>> from django.db Import models>>> class Poll (models. Model): ...     Question = models. Charfield (max_length=200)     ... Pub_date = models. Datetimefield (' date published ')     ... Class Meta: ...         App_label = ' Test '

Explain why you can do it, see in Backtracking (Traceback),/usr/lib/python2.7/site-packages/django/db/models/base.py mentions the file:

If GetAttr (meta, ' App_label ', none) is None: # figure out the App_label by looking one level up    .    # for ' Django.contrib.sites.models ', this would is ' sites '.    Model_module = sys.modules[new_class.__module__]    Kwargs = {"App_label": Model_module.__name__.split ('. ') [-2]} else:    Kwargs = {}

Where is the meta-class defined? , see above in the file.

Python Django Shell Debugging

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.