我在django中有一个扩展的UserProfile模型:
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
#other things in that profile
Run Code Online (Sandbox Code Playgroud)
还有一个signals.py:
from registration.signals import user_registered
from models import UserProfile
from django.contrib.auth.models import User
def createUserProfile(sender, instance, **kwargs):
profile = users.models.UserProfile()
profile.setUser(sender)
profile.save()
user_registered.connect(createUserProfile, sender=User)
Run Code Online (Sandbox Code Playgroud)
我确保信号通过以下方式注册__init__.py:
import signals
Run Code Online (Sandbox Code Playgroud)
那么应该为每个注册的用户创建一个新的UserProfile,对吧?但事实并非如此.我尝试登录时总是得到"UserProfile匹配查询不存在"错误,这意味着数据库条目不存在.
我应该说我使用django-registration,它提供user_registered信号.
重要应用程序的结构是,我有一个名为"users"的应用程序,我有:models.py,signals.py,urls.py和views.py(以及其他一些在这里无关紧要的事情) ).UserProfile类在models.py中定义.
更新:我将signals.py更改为:
from django.db.models.signals import post_save
from models import UserProfile
from django.contrib.auth.models import User
def create_profile(sender, **kw):
user = kw["instance"]
if kw["created"]:
profile = UserProfile()
profile.user = user
profile.save()
post_save.connect(create_profile, sender=User)
Run Code Online (Sandbox Code Playgroud)
但现在我得到了"IntegrityError":
"列user_id不是唯一的"
编辑2:
我找到了.看起来我以某种方式注册了两次信号.此处描述了解决方法: …
这个字符串:
"CREATE USER %s PASSWORD %s", (user, pw)
Run Code Online (Sandbox Code Playgroud)
总是扩大到:
CREATE USER E'someuser' PASSWORD E'somepassword'
Run Code Online (Sandbox Code Playgroud)
谁能告诉我为什么?
编辑:上面的扩展字符串是我的数据库在错误消息中返回的字符串.我正在使用psycopg2来访问我的postgres数据库.真正的代码如下所示:
conn=psycopg2.connect(user=adminuser, password=adminpass, host=host)
cur = conn.cursor()
#user and pw are simple standard python strings the function gets as parameter
cur.execute("CREATE USER %s PASSWORD %s", (user, pw))
conn.commit()
Run Code Online (Sandbox Code Playgroud) 我发现我需要在内核模块中构建一个新的sk_buff结构并将其传递给我的网络设备,但我无法弄清楚的是如何为简单的原始以太网数据包设置结构变量.
这一定很简单,但我真的很感激,如果有人能给我一个如何将sk_buff放在一起的示例代码.
让我们说我有一个看起来像这样的django模型:
class question(models.Model):
order = models.IntegerField('Position')
question = models.CharField(max_length= 400)
answer = models.TextField()
published = models.BooleanField()
def __unicode__(self):
return self.question
Run Code Online (Sandbox Code Playgroud)
在我看来,我会显示订单字段中按升序排序的所有问题.
我的问题是:是否有一种简单的方法来编辑django管理界面中的订单字段?现在我必须去编辑问题,而不是查看订单字段中的数字,甚至可能重新排序所有其他项目.我真正想要的是在管理页面上的一些"向上和向下" - 所有问题都列在其中.
那可能吗?
在我的应用程序中我有AUTH_PROFILE_MODULE设置users.UserProfile.此UserProfile有一个函数create,当新用户注册时,应该调用该函数,然后创建UserProfile条目.
根据django-registration文档,所有需要做的是profile_callback在我的urls.py中设置条目.我看起来像这样:
url(r'^register/$', register, {'form_class': RecaptchaRegistrationForm,
'profile_callback': UserProfile.objects.create,
'backend': 'registration.backends.default.DefaultBackend',},
name='registration_register')
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
异常值:register()得到一个意外的关键字参数'profile_callback'
那么我必须把它放在哪里才能使它工作?
为什么我的background.html页面会抛出这个:
Uncaught SyntaxError: Unexpected token < 在第1行
这是实际的html:
<html>
<head>
<script type="text/javascript" src="fancy-settings/source/lib/store.js"></script>
<script type="text/javascript" src="background.js"></script>
</head>
<body></body>
</html>
Run Code Online (Sandbox Code Playgroud)
所以chrome抱怨第一次打开"<",我不明白为什么.
我正在使用postgresql服务器,我想禁止我的用户查看同一服务器上的其他数据库.
基本上\l应该只列出他自己的数据库.
我很确定我需要撤销用户的权利,但我无法在文档中找到它.
每次执行特定的cronjob时,我都会收到以下邮件.当我直接调用它时,调用的脚本运行正常,甚至来自cron.所以我得到的消息不是一个实际的错误,因为脚本完全按照它应该做的去做.
这是cron.d条目:
* * * * * root /bin/bash -l -c "/opt/get.sh > /tmp/file"
Run Code Online (Sandbox Code Playgroud)
和get.sh脚本本身:
#!/bin/sh
#group and url
groups="foo"
url="https://somehost.test/get.php?groups=${groups}"
# encryption
pass='bar'
method='aes-256-xts'
pass=$(echo -n $pass | xxd -ps | sed 's/[[:xdigit:]]\{2\}/&/g')
encrypted=$(wget -qO- ${url})
decoded=$(echo -n $encrypted | awk -F '#' '{print $1}')
iv=$(echo $encrypted | awk -F '#' '{print $2}' |base64 --decode | xxd -ps | sed 's/[[:xdigit:]]\{2\}/&/g')
# base64 decode input and save to file
output=$(echo -n $decoded | base64 --decode | openssl enc -${method} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我从django-social-auth获取的OAuth令牌来访问用户日历.
所以在我设置的django-social-auth配置中:
GOOGLE_CONSUMER_KEY = 'anonymous'
GOOGLE_CONSUMER_SECRET = 'anonymous'
GOOGLE_OAUTH_EXTRA_SCOPE = ['https://www.google.com/calendar/feeds/']
Run Code Online (Sandbox Code Playgroud)
当用户从谷歌回来时,我在数据库中得到一个如下所示的条目:
{u'access_token': u'oauth_token_secret=vvvv&oauth_token=xxxx'}
Run Code Online (Sandbox Code Playgroud)
但现在,当我尝试做这样的事情时:
import gdata.calendar.client
client = gdata.calendar.client.CalendarClient()
client.auth_token = gdata.gauth.OAuthHmacToken('anonymous', 'anonymous', 'xxxx', 'vvvv', gdata.gauth.ACCESS_TOKEN)
client.GetOwnCalendarsFeed()
Run Code Online (Sandbox Code Playgroud)
我总是得到:
gdata.client.Unauthorized: Unauthorized - Server responded with: 401
<HEAD>
<TITLE>Token invalid - Invalid AuthSub token.</TITLE>
</HEAD>
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
有没有办法通过SQL语句停用postgres用户帐户?
我想阻止用户使用他的数据库,但不删除用户或他的数据库.
django ×4
postgresql ×3
bash ×1
c ×1
cron ×1
crontab ×1
django-admin ×1
gdata ×1
html ×1
javascript ×1
linux ×1
linux-kernel ×1
oauth ×1
psycopg ×1
python ×1
raw-sockets ×1
sockets ×1
sql ×1