在Django管理中,我可以根据我想要的任何列来排序每个表,而不必在模型中指定任何内容:
在单击列标题后,通常会出现一个描述顺序的小箭头。
admin.py:
from django.contrib import admin
from .models import User
from .resources import UserAdminResource
from import_export.admin import ExportActionModelAdmin
class UserAdmin(ExportActionModelAdmin, admin.ModelAdmin):
我必须从外部API获取一些数据,并将其显示为django管理页面中的列。我尝试将代码作为一个类级变量赋值,但它只在django服务器开始时获取数据,并且它不能作为函数级调用工作,因为不知何故请求库在这里冻结了django。
所以这两个例子对我来说都不适用:
class NewModelAdmin(admin.ModelAdmin):
variable = requests.get(...) # it's executing only once
class NewModelAdmin(admin.ModelAdmin):
def some_column(self, obj
我最近扩展了UserProfile,所以我的admin.py看起来像这样:
from django.contrib import admin
from django.contrib.auth.models import User
from models import UserProfile
from django.contrib.auth.admin import UserAdmin
admin.site.unregister(User)
class UserProfileInline(admin.StackedInline):
model = UserPr
我只是使用userena来创建用户函数,所有操作都很好,除了当我尝试在管理页面登录时会出现这个错误,而且我使用django 1.9.7和userena 2.0.1。我读了一些旧的帖子,上面写着删除'django.contrib.sites'中的INSTALLED_APPS,但是如果我删除它,userena就不能工作了。
以下是错误信息:
DoesNotExist at /admin/login/
Site matching query does not exist.
Request Method: GET
Request URL: http://127.0.0
我已经设置了django教程的第1部分,在尝试访问投票应用程序时,我收到了以下'Page (404)‘错误:
Page not found (404)
Request Method: GET
Request URL: http://proto.slc.venturedata.com/polls/
Raised by: polls.views.index
Using the URLconf defined in proto.urls, Django tried these URL patterns, in this order:
1. polls/
2
我已经在django中创建了此应用程序,但我无法访问该应用程序。CMD显示属性错误:模块'hello.views‘没有属性’索引‘
VIEWS.PY
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello World !!!')
URLS.PY/admin
from django.contrib import admin
from django.urls import path,
我正在建立一个基于高度自定义的django管理实例的网站,并遇到了用户配置文件作为内联到user_admin的问题
长话短说,不管我在admin.StackedInline实例中为max_num和extra设置了什么,它允许每个用户最多2个配置文件-如果用户有现有的配置文件,默认情况下会有一个空白配置文件
有人知道我如何调整它,使其只显示单个内联配置文件,而不求助于某些JS前端hack吗?
相关代码来自: profiles.admin.py
from django.contrib import admin
from django.contrib.auth.models import User
我知道以前有人问过这个问题,但我还没有找到一个解决我的情况的答案。
我正在查看Django ,我已经按照教程中的原样逐字设置了第一个URL,但是当我转到时,它给出了这个错误:
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/ ^% [name='index']
^admin/
The current URL, polls/, didn't match any of these.
我使用的是Django 1.10.5和Pytho
当我添加一个名为advertisements的应用程序(添加模型,INSTALLED_APPS中的admin +寄存器)时,它没有列在管理界面中(很难看到,但它在微秒后消失)。
models.py
from django.db import models
# Create your models here.
class Advertisement(models.Model):
pass
admin.py
from django.contrib import admin
from .models import Advertisement
# Register your model