小编Gr1*_*r1N的帖子

如何为django admin创建自定义页面?

我想为没有模型的管理面板创建自定义页面.首先我将index.html复制到项目文件夹:

mysite/
    templates/
        admin/
            index.html
Run Code Online (Sandbox Code Playgroud)

然后添加到应用程序阻止我的代码:

<div class="module">
    <table summary="{% blocktrans with name="preferences" %}Models available in the preferences application.{% endblocktrans %}">
        <caption><a href="preferences" class="section">{% blocktrans with name="preferences" %}Preferences{% endblocktrans %}</a></caption>
            <tr>
                <th scope="row"><a href="preferences">Preferences</a></th>
                <td><a href="preferences" class="changelink">{% trans 'Change' %}</a></td>
            </tr>
    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

这很好用,然后我创建新页面/templates/admin/preferences/preferences.html并添加到urls.py:

url(r'^admin/preferences/$', TemplateView.as_view(template_name='admin/preferences/preferences.html')),
Run Code Online (Sandbox Code Playgroud)

并将代码添加到preferences.html:

{% extends "admin/base_site.html" %}
{% block title %}Test page{% endblock %}
Run Code Online (Sandbox Code Playgroud)

运行它并查看错误消息"请求的管理页面不存在.".我做错了什么?

python django django-admin

38
推荐指数
6
解决办法
4万
查看次数

从url解析查询部分

我想从url解析查询部分,这是我的代码:

>>> from urlparse import urlparse, parse_qs
>>> url = '/?param1&param2=2'
>>> parse_qs(urlparse(url).query)
>>> {'param2': ['23']}
Run Code Online (Sandbox Code Playgroud)

此代码看起来不错,但"parse_qs"方法丢失了诸如"param1"或"param1 ="之类的查询参数.我可以用stantard库解析查询部分并保存所有参数吗?

python urlparse

17
推荐指数
1
解决办法
2万
查看次数

与主管和virtualenv监督celerybeat

我的celerybeat.conf

[program:celerybeat]
command=/path/app/env/bin/celery beat -A project.tasks --loglevel=INFO
environment=PYTHONPATH=/path/app/env/bin

user=nobody
numprocs=1
stdout_logfile=/var/log/celeryd.log
stderr_logfile=/var/log/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=998
Run Code Online (Sandbox Code Playgroud)

当我启动主管时,我收到一个错误:

pidfile_fd = os.open(self.path, PIDFILE_FLAGS, PIDFILE_MODE)
celery.platforms.LockFailed: [Errno 13] Permission denied: '/celerybeat.pid'
Run Code Online (Sandbox Code Playgroud)

不知道怎么解决这个问题?

python celery supervisord celerybeat

13
推荐指数
2
解决办法
7956
查看次数

svn diff不显示修改的外部文件

我在本地仓库中添加了一些更改并运行svn diff,但diff输出为空.但svn status标记我的文件已修改.这是文件是外部项目,我怎么能用diff这个命令?

svn version-control

7
推荐指数
1
解决办法
4384
查看次数

如何使用GitPython计算未发布的提交?

随着git status我可以了解未公布的提交计数信息:

» git status             
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)

我想用GitPython获取未发布的提交(或计数).我找到的文档repo.git.status(),但这不是我想要的.

python git gitpython

3
推荐指数
1
解决办法
2445
查看次数

如何编写基于ListView的类的get方法

我尝试为基于 ListView 的类编写 get 方法,我想从模板中的表单获取请求,并从请求返回带有过滤器的模型。这是我的代码的一部分:

class SearchListView(ListView):
    context_object_name = 'projects_list'
    template_name = 'projects/search.html'
    paginate_by = 10

    def get(self, request, *args, **kwargs):
        do smth??
        return self.render_to_response(??)
Run Code Online (Sandbox Code Playgroud)

我的表格:

<form class="well form-search" action="/search/" method="get">
    <input type="text" class="input-medium search-query" name="q">
    <button type="submit" class="btn">Search</button>
</form>
Run Code Online (Sandbox Code Playgroud)

请给我一些例子。

django django-views

2
推荐指数
1
解决办法
4541
查看次数

从文件内容中检测文件类型,而不是文件名

可能重复:
如何在python中找到文件的mime类型?

我想检测文件的类型,但我不想查看扩展名,因为它可能不正确.该mimetypes模块基于文件名.

是否有标准的方式来查看文件?

python

2
推荐指数
1
解决办法
9308
查看次数

查询许多(名称等于)键

例如,我有主键[1,2,3,4]的列表我想做这样的smth:

Player.objects.order_by('-cup_points').exclude(pk=[1,2,3,4])
Run Code Online (Sandbox Code Playgroud)

但参数必须是字符串或数字,而不是"列表".我可以这样做吗?

python django django-templates

0
推荐指数
1
解决办法
51
查看次数