Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django管理界面没有';t秀应用程序_Python_Django_Django Admin - Fatal编程技术网

Python Django管理界面没有';t秀应用程序

Python Django管理界面没有';t秀应用程序,python,django,django-admin,Python,Django,Django Admin,我试着在我的系统中加入一些微小的差异来遵循这一点 我使用sqLite而不是mysql,我使用django 1.4 我认为教程是在1.4发布之前编写的 我只有一个在教程中命名的应用程序-todo。我试图在django的管理界面上显示应用程序,但我无法做到这一点 在终端上键入python manage.py syncdb命令时,会显示以下错误消息: 下面您可以看到我的项目的文件 型号.py # -*- coding: utf-8 -*- from django.db import mod

我试着在我的系统中加入一些微小的差异来遵循这一点

  • 我使用sqLite而不是mysql,我使用django 1.4
  • 我认为教程是在1.4发布之前编写的
我只有一个在教程中命名的应用程序-todo。我试图在django的管理界面上显示应用程序,但我无法做到这一点

在终端上键入python manage.py syncdb命令时,会显示以下错误消息:

下面您可以看到我的项目的文件


型号.py

# -*- coding: utf-8 -*-


from django.db import models
from django.contrib import admin
admin.autodiscover()

# Create your models here.

# For this application, we will need two models:
#                                              one representing a list,
#                                              and one representing an item in a list.


# this class will be a database table named list
class List(models.Model): 

  title = models.CharField(max_length=250, unique=True) 

  # __str__ method is like toString() in java
  def __str__(self): 

    return self.title 

  class Meta: 

    ordering = ['title'] 

  class Admin: 

    pass




# i need this for  Item Class    
import datetime 



PRIORITY_CHOICES = ( 

  (1, 'Low'), 

  (2, 'Normal'), 

  (3, 'High'), 

) 


# this class will be a database table named item
class Item(models.Model): 

  # this will create a charfield column named "title" in database
  title = models.CharField(max_length=250) 


  # created_date will be a DATETIME column in the database
  # datetime.datetime.now is a standard Python function
  created_date = models.DateTimeField(default=datetime.datetime.now) 


  # default priority level will be 2 as in "Normal" in PRIORITY_CHOICES
  # using choices argument as choices=PRIORITY_CHOICES , Django will allow only 1,2 and 3 as we want to
  priority = models.IntegerField(choices=PRIORITY_CHOICES, default=2) 


  # this will create a boolean column named "completed" in database
  completed = models.BooleanField(default=False)

  todo_list = models.ForeignKey(List) 

  def __str__(self): 

    return self.title 

  class Meta: 

    # We have specified that list items should be ordered by two columns: priority and title.
    # The - in front of priority tells Django to use descending order for the priority column,
    # so Django will include ORDER BY priority DESC title ASC in its queries whenever it deals with list items.
    ordering = ['-priority', 'title'] 

  class Admin: 

    pass
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/Users/ihtechnology/Desktop/envi/db_gtd/sqlite3.db', 
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      
        'PORT': '',                      
    }
}

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    # I ADDED MY APPLICATION HERE SO IN CAN BE INSTALLED INTO PROJECT AS OTHER DEFAULT DJANGO APPS
    'todo',
)
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)
from todo.models import List
from todo.models import Item
from django.contrib import admin

admin.site.register(List)
admin.site.register(Item)

设置.py

# -*- coding: utf-8 -*-


from django.db import models
from django.contrib import admin
admin.autodiscover()

# Create your models here.

# For this application, we will need two models:
#                                              one representing a list,
#                                              and one representing an item in a list.


# this class will be a database table named list
class List(models.Model): 

  title = models.CharField(max_length=250, unique=True) 

  # __str__ method is like toString() in java
  def __str__(self): 

    return self.title 

  class Meta: 

    ordering = ['title'] 

  class Admin: 

    pass




# i need this for  Item Class    
import datetime 



PRIORITY_CHOICES = ( 

  (1, 'Low'), 

  (2, 'Normal'), 

  (3, 'High'), 

) 


# this class will be a database table named item
class Item(models.Model): 

  # this will create a charfield column named "title" in database
  title = models.CharField(max_length=250) 


  # created_date will be a DATETIME column in the database
  # datetime.datetime.now is a standard Python function
  created_date = models.DateTimeField(default=datetime.datetime.now) 


  # default priority level will be 2 as in "Normal" in PRIORITY_CHOICES
  # using choices argument as choices=PRIORITY_CHOICES , Django will allow only 1,2 and 3 as we want to
  priority = models.IntegerField(choices=PRIORITY_CHOICES, default=2) 


  # this will create a boolean column named "completed" in database
  completed = models.BooleanField(default=False)

  todo_list = models.ForeignKey(List) 

  def __str__(self): 

    return self.title 

  class Meta: 

    # We have specified that list items should be ordered by two columns: priority and title.
    # The - in front of priority tells Django to use descending order for the priority column,
    # so Django will include ORDER BY priority DESC title ASC in its queries whenever it deals with list items.
    ordering = ['-priority', 'title'] 

  class Admin: 

    pass
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/Users/ihtechnology/Desktop/envi/db_gtd/sqlite3.db', 
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      
        'PORT': '',                      
    }
}

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    # I ADDED MY APPLICATION HERE SO IN CAN BE INSTALLED INTO PROJECT AS OTHER DEFAULT DJANGO APPS
    'todo',
)
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)
from todo.models import List
from todo.models import Item
from django.contrib import admin

admin.site.register(List)
admin.site.register(Item)

url.py

# -*- coding: utf-8 -*-


from django.db import models
from django.contrib import admin
admin.autodiscover()

# Create your models here.

# For this application, we will need two models:
#                                              one representing a list,
#                                              and one representing an item in a list.


# this class will be a database table named list
class List(models.Model): 

  title = models.CharField(max_length=250, unique=True) 

  # __str__ method is like toString() in java
  def __str__(self): 

    return self.title 

  class Meta: 

    ordering = ['title'] 

  class Admin: 

    pass




# i need this for  Item Class    
import datetime 



PRIORITY_CHOICES = ( 

  (1, 'Low'), 

  (2, 'Normal'), 

  (3, 'High'), 

) 


# this class will be a database table named item
class Item(models.Model): 

  # this will create a charfield column named "title" in database
  title = models.CharField(max_length=250) 


  # created_date will be a DATETIME column in the database
  # datetime.datetime.now is a standard Python function
  created_date = models.DateTimeField(default=datetime.datetime.now) 


  # default priority level will be 2 as in "Normal" in PRIORITY_CHOICES
  # using choices argument as choices=PRIORITY_CHOICES , Django will allow only 1,2 and 3 as we want to
  priority = models.IntegerField(choices=PRIORITY_CHOICES, default=2) 


  # this will create a boolean column named "completed" in database
  completed = models.BooleanField(default=False)

  todo_list = models.ForeignKey(List) 

  def __str__(self): 

    return self.title 

  class Meta: 

    # We have specified that list items should be ordered by two columns: priority and title.
    # The - in front of priority tells Django to use descending order for the priority column,
    # so Django will include ORDER BY priority DESC title ASC in its queries whenever it deals with list items.
    ordering = ['-priority', 'title'] 

  class Admin: 

    pass
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/Users/ihtechnology/Desktop/envi/db_gtd/sqlite3.db', 
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      
        'PORT': '',                      
    }
}

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    # I ADDED MY APPLICATION HERE SO IN CAN BE INSTALLED INTO PROJECT AS OTHER DEFAULT DJANGO APPS
    'todo',
)
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)
from todo.models import List
from todo.models import Item
from django.contrib import admin

admin.site.register(List)
admin.site.register(Item)

admin.py

# -*- coding: utf-8 -*-


from django.db import models
from django.contrib import admin
admin.autodiscover()

# Create your models here.

# For this application, we will need two models:
#                                              one representing a list,
#                                              and one representing an item in a list.


# this class will be a database table named list
class List(models.Model): 

  title = models.CharField(max_length=250, unique=True) 

  # __str__ method is like toString() in java
  def __str__(self): 

    return self.title 

  class Meta: 

    ordering = ['title'] 

  class Admin: 

    pass




# i need this for  Item Class    
import datetime 



PRIORITY_CHOICES = ( 

  (1, 'Low'), 

  (2, 'Normal'), 

  (3, 'High'), 

) 


# this class will be a database table named item
class Item(models.Model): 

  # this will create a charfield column named "title" in database
  title = models.CharField(max_length=250) 


  # created_date will be a DATETIME column in the database
  # datetime.datetime.now is a standard Python function
  created_date = models.DateTimeField(default=datetime.datetime.now) 


  # default priority level will be 2 as in "Normal" in PRIORITY_CHOICES
  # using choices argument as choices=PRIORITY_CHOICES , Django will allow only 1,2 and 3 as we want to
  priority = models.IntegerField(choices=PRIORITY_CHOICES, default=2) 


  # this will create a boolean column named "completed" in database
  completed = models.BooleanField(default=False)

  todo_list = models.ForeignKey(List) 

  def __str__(self): 

    return self.title 

  class Meta: 

    # We have specified that list items should be ordered by two columns: priority and title.
    # The - in front of priority tells Django to use descending order for the priority column,
    # so Django will include ORDER BY priority DESC title ASC in its queries whenever it deals with list items.
    ordering = ['-priority', 'title'] 

  class Admin: 

    pass
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/Users/ihtechnology/Desktop/envi/db_gtd/sqlite3.db', 
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      
        'PORT': '',                      
    }
}

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
    # I ADDED MY APPLICATION HERE SO IN CAN BE INSTALLED INTO PROJECT AS OTHER DEFAULT DJANGO APPS
    'todo',
)
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)
from todo.models import List
from todo.models import Item
from django.contrib import admin

admin.site.register(List)
admin.site.register(Item)


问题在于,您正在从
模型
模块中运行
admin.autodiscover()
,因此在调用过程中会发生以下情况:

  • Django在所有已安装的应用程序中查找所有
    admin
    模块,并导入它们
  • 导入每个
    admin
    模块时,位于
    admin
    模块顶部的导入当然会正确运行
  • admin
    模块从todo.models导入列表导入
    (大概)
  • todo.models
    模块尚不可用,因为在运行
    admin.autodiscover()
    时(在回溯底部的第3帧),它仍由
    load\u应用程序导入(回溯底部的第6帧)
  • tl;博士

    你只是有一个循环导入,但我想解释一下,以便弄清楚原因

    解决方案
    admin.autodiscover()
    移动到主
    URL
    模块。

    这是由于
    循环导入问题造成的:

    +--> +/todo/models.py #line 6
    |    |
    |    +->**admin.autodiscover()**
    |      +
    |      |
    |      +-->/django/contrib/admin/__init__.py #line 29
    |         +
    |         |
    |         +->/django/utils/importlib.py # line 35
    |           +
    |           |
    |           +-->/todo/admin.py #line 1
    |           |
    |           +->from todo.models import List
    |           |
    |           |
    +-----------+
    
    您的
    admin
    样式旧,请尝试新样式


    对于django管理面板中未显示的标题

    我使用的是django 1.4,新的管理样式从1.6开始,我解决了问题,但感谢您的帮助,我不确定这是否适用于此问题;关于根本原因,请参见其他答案,这似乎根本无法解决。