社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

kinegratii

kinegratii 最近创建的主题
kinegratii 最近回复了

1 admin.py

admin.site.register(User, App)

第二个参数必须是一个ModelAdmin的class

2 urls

url(r'^admin/', admin.site.urls),

忘记加上include

8 年前
回复了 kinegratii 创建的主题 » 求助关于错误The 'image' attribute has no file associated with it.

img标签src属性引用blank=True的ImageField需要判断图片是否存在

    {% if post.image %}
        <img src= '{{ post.image.url }}'/>
    {% else %}
        <p>暂无图片</p>
    {%endif %}
8 年前
回复了 kinegratii 创建的主题 » 【供新人参考的项目】图书管理系统(Django1.9.1+Bootstrap3)

已Star,表示很赞

8 年前
回复了 kinegratii 创建的主题 » 手动创建的TEMPLATE_DIRS中一直出问题,求帮助

参考 http://kinegratii.com/articles/2015-01-20-the-structure-of-django-project

settings.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, templates).replace('\\', '/'),
)

templates目录和manage.py同一级

pro/
    --pro/
    --app1/
    --app2/
    --templates/
        |--index.html
   --manage.py
9 年前
回复了 kinegratii 创建的主题 » 关于django中model的疑问

Django1.7+中syncdb命令已经废弃了,应该使用migrate命令同步数据库,具体请参考教程

刚学的时候最好请参照官网对应的教程学习,不同版本的教程有出入。

9 年前
回复了 kinegratii 创建的主题 » Djnago如何实现form下拉列表的动态加载?

这是因为,choices参数的值是立即计算的,第一次是什么以后就是什么了

__init__函数中使用动态加载

    self.fields['queue'].choices = ((x.que,x.disr) for x in Queue.objects.all()))
9 年前
回复了 kinegratii 创建的主题 » Awesome Django(常用的第三方APP列表)

@olivetree 只是一些第三方应用的大集合,需要的时候有个参考

9 年前
回复了 kinegratii 创建的主题 » dump to json in python class object

更进一步,支持对象嵌套;

def obj2dict(obj):
      # 基本数据类型,直接返回
    if not hasattr(obj,'__dict__'):
        return obj
    res = {}
    for k,v in obj.__dict__.items():
        if k.startswith('-'):
            continue
        if isinstance(v,list):
            ele = [obj2dict(item) for item in v]
        else:
            ele = obj2dict(v)
        res[k] = ele
    return res

使用方法:

json.dumps(obj, default=obj2dict)

具体可参考:https://github.com/kinegratii/PySnippet/tree/master/obj2json

9 年前
回复了 kinegratii 创建的主题 » 大神来看下问题.

Python compatibility Django 1.7 requires Python 2.7 or above, though we highly recommend the latest minor release. Support for Python 2.6 has been dropped and support for Python 3.4 has been added.

9 年前
回复了 kinegratii 创建的主题 » 能不能让admin后台中只显示对应user的object?

ModelAdmin不是有get_queryset/queryset方法吗? https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_queryset

参考Django1.5新引入的AUTH_USER_MODEL https://docs.djangoproject.com/en/dev/topics/auth/customizing/