问题标签 [django-1.5]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
4389 浏览

django - Django注册登录重定向

使用 django-registration,我在 settings.py 中有:

当我试图访问一个页面(退出)http://localhost:8000/surfboards/current/时,我被重定向到http://localhost:8000/accounts/login/?next=/surfboards/current/

在这种情况下,如果next指定了参数,我希望在登录成功后重定向到此页面,而不是默认的LOGIN_REDIRECT_URL.

现在,我总是被重定向到,只有在没有指定的情况下http://localhost:8000/,这才是我想要的。next

谢谢,

0 投票
0 回答
1517 浏览

python - 从 1.4.3 升级到 1.5.1 后 Django 错误“secret_key 设置不能为空”

我刚刚使用pip install django --upgrade. 升级后,我的开发站点开始出现内部服务器错误。我试图运行./manage.py命令,但它告诉我“secret_key 设置不能为空”。我检查了我的settings.py文件,它确实有一个SECRET_KEY值。所以我不知道那里发生了什么。其他人有同样的问题吗?

0 投票
2 回答
3899 浏览

django - Django 1.5:对 AbstractBaseUser 和权限的理解

我创建了一个用户应用程序MyUser,它是AbstractBaseUser. 我的印象是该模型MyUser将取代标准Auth.User,只要它在settings.py

AUTH_PROFILE_MODULE = 'profile.MyUser'

我现在的问题是我无法为在 MyUser 模型中注册的用户设置权限。当我尝试设置组成员资格和权限时,出现错误User' instance expected, got <MyUser: username>

如何将我的用户模型的用户添加到权限和正确的组?

0 投票
1 回答
84 浏览

facebook-login - 是否有任何 django 包提供对社交身份验证的支持以及 Django 1.5 中引入的自定义用户模型?

我现在需要单独的 Facebook 身份验证。但是我们以后可能需要其他的,比如 twitter 和 google。根据我的研究,django-social-auth 和 django-allauth 都还没有进行兼容性更改。有什么建议么?

0 投票
2 回答
7043 浏览

django - Custom User Model error

I'm trying to set up my custom user model in Django. The reason is that I want to use email as the username, and remove the username field entirely. I've run into a error, that I just can't figure out.

I've googled like crazy, but haven't found too many pages about this error message. I have found some pages, with suggestions on how to solve it, but none of the suggestions have worked for me.

My code: I've set the custom user model. I have declared the custom user model AUTH_USER_MODEL = 'app.MyUser' in settings.py. I have also set up a custom UserManager:

I've tried to declare to different types of UserAdmins, none of which is making any difference,the first one I tried was;

I've commented out the two attributes add_form and form because they raised some form errors I wanted to get back to at a later point.

The second UserAdmin was made, after reading about a possible fix here. This didn't help the situation though;

I've also tried deleting all tables in the db with no luck.

I would be eternally greatful to anyone who even looks at the problem. And if any one were to solve this, I would try my best to talk my wife into naming our firstborn after the Avatar that gave me a solution so that I could go on living my life.

EDIT: I tried setting the AUTH_USER_MODELto mainfolder.app.MyUserI'm sure the "mainfolder" is on the pythonpath. init.py in the app should be correct. The new settings.py gave the following server error; auth.user: AUTH_USER_MODEL is not of the form 'app_label.app_name'.admin.logentry: 'user' has a relation with model smartflightsearch.SFSdb.MyUser, which has either not been installed or is abstract.registration.registrationprofile: 'user' has a relation with model, which has either not been installed or is abstract. A new clue I don't know how to interpret..

0 投票
2 回答
4329 浏览

python - Django中的详细弃用警告

从 django 1.3 升级到 django 1.5 后,我DeprecationWarnings在测试运行期间开始看到这些:

path_to_virtualenv/lib/python2.6/site-packages/django/http/request.py:193:DeprecationWarning:HttpRequest.raw_post_data 已被弃用。请改用 HttpRequest.body。

我在项目内部进行了搜索,但raw_post_data一无所获。所以没有直接在项目中使用。然后,我手动检查INSTALLED_APPS并发现该raven模块仍在使用raw_post_data,这是原因,但是..

DeprecationWarning是否可以在试运行期间查看原因?如何使这些警告更详细?

0 投票
1 回答
13239 浏览

python - 为什么在 django.forms.CharField 中缺少“空白”,但在 django.db.models.CharField 中存在?

背景

我有一个模型,其中两个字段设置为空白:

问题是我想在max_length构建表单时动态设置,所以我有一个自定义表单:

注意:这两个长度值实际上是从数据库中获取的,但我选择不包含该代码以使示例更短。

问题

当我使用这些自定义字段时,该blank选项将被覆盖/忽略。

我尝试将 max_length、小部件和验证器添加到现有字段,如下所示:

执行此操作时,该blank选项有效,但动态 max_length 不会应用于表单。

我试图查看 django 源代码,但我很新,所以现在接受的内容太多了。

有什么方法可以实现吗?

0 投票
1 回答
19991 浏览

django - Django:user.has_perm 始终为真且用户不是超级用户。为什么?

我在我的 Django 1.5 应用程序中分配了一个用户的权限。当我列出所有用户权限时

我可以看到一个权限(这是正确的和想要的)。该用户也不是超级用户,也不是管理员。

但是,如果我尝试使用user.has_perm,我总是会得到True任何提交的许可请求的回报。

如果用户是超级用户/管理员,我会期望这种行为。为什么非超级用户总是收到True每个请求?我错过了任何设置吗?

0 投票
1 回答
358 浏览

python - Django模板:本地化从简单标签返回的数字

我希望这个问题不在这里,我用谷歌搜索了很长时间,没有找到任何东西。我在模板中格式化数字时遇到问题,但有点特别。也许,这就是如何对从简单标签返回的值调用过滤器的整个问题。所以,首先,一些事实:

  • 使用 python 2.7 和 Django 1.5
  • 在捷克语中,我们使用逗号“,”作为小数分隔符,可选空格“”作为千位分隔符(更常见的是写没有千位分隔符的数字)。
  • 通常,写数字{{ price }}是打印例如16,0

出于某种原因,我必须使用模板中的数字:

count basic 是简单的标签:

结果是没有打印为16.0。我已将 l10n 设置settings.py为 True:

我也发现“人性化”可以工作,但首先,我不知道如何使用从另一个简单标签返回的值调用简单标签/过滤器(也许使用with?),其次,如果它适用于普通数字,为什么不适用于数字从简单标签返回?号码是否返回错误?应该转换吗?我也尝试过返回值Decimal()并且不起作用。

任何简单的工作解决方案都值得赞赏。

0 投票
1 回答
277 浏览

django - 在 Django 1.5 中使用密码确认操作

如何在 Django 1.5 中创建“使用密码确认”表单?我将创建一个禁用用户帐户的功能,但如果用户无法提供正确的密码,则不应禁用该帐户。我尝试过使用 FormView 和form_class=AuthenticationForm,但它同时显示了用户名和密码,我只需要密码,因为用户已经登录。