包装第 3 方 Django 应用程序的视图时出错? (Facebook、django-socialregistration、django-profiles)
我正在使用 django-socialregistration 来管理我的网站与 Facebook 的连接。
当用户单击“连接 Facebook”按钮时,我可以自动创建一个新的 Django 用户并登录。但是,我还需要为他们创建一个 UserProfile (我的 AUTH_PROFILE_MODULE)记录,其中包含他们的 Facebook 个人资料信息(电子邮件、姓名、位置)。
我相信我需要覆盖 Socialregistration 的“设置”视图,以便我可以使用 UserProfile 执行我需要执行的操作。我已将以下内容添加到项目的 urls.py 文件中:
url(r'^social/setup/$', 'myapp.views.socialreg.pre_setup', name='socialregistration_setup'),
我的自定义视图位于“/myapp/views/socialreg.py”,看起来像
from socialregistration.forms import UserForm
def pre_setup(request, template='socialregistration/setup.html',
form_class=UserForm, extra_context=dict()):
# will add UserProfile storage here...
return socialregistration.views.setup(request, template, form_class, extra_context)
:我要覆盖的视图签名看起来像这样:
def setup(request, template='socialregistration/setup.html',
form_class=UserForm, extra_context=dict()):
...
我收到错误“ViewDoesNotExist at /social/setup/: Could not import myapp.views.socialreg. Error was: No module named Socialregistration.views” 当我尝试上面的解决方案时。
当我不尝试覆盖视图时,社交注册应用程序工作正常,因此它可能已正确安装在站点包中。有人知道我做错了什么吗?
I'm using django-socialregistration to manage my site's connection with Facebook.
When a user clicks the "Connect with Facebook" button, I am able to automatically create a new Django user and log them in. However, I also need to create a UserProfile (my AUTH_PROFILE_MODULE) record for them which contains their Facebook profile information (email, name, location).
I believe I need to override socialregistration's "setup" view so I can do what I need to do with UserProfile. I've added the following to my project's urls.py file:
url( r'^social/setup/$', 'myapp.views.socialreg.pre_setup', name='socialregistration_setup'),
My custom view is here "/myapp/views/socialreg.py" and looks like:
from socialregistration.forms import UserForm
def pre_setup(request, template='socialregistration/setup.html',
form_class=UserForm, extra_context=dict()):
# will add UserProfile storage here...
return socialregistration.views.setup(request, template, form_class, extra_context)
The socialregistration view signature I'm overriding looks like this:
def setup(request, template='socialregistration/setup.html',
form_class=UserForm, extra_context=dict()):
...
I'm getting the error "ViewDoesNotExist at /social/setup/: Could not import myapp.views.socialreg. Error was: No module named socialregistration.views" when I try the solution above.
The socialregistration app is working fine when I don't try to override the view, so it is likely installed correctly in site-packages. Anyone know what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,正如蒂姆指出的,这个特定问题与路径相关。
从更大的角度来看,实现我想要的方法(在 django-socialregistration 创建用户时创建链接的 UserProfile)最好通过将自定义表单传递到 Socialregistration 的“设置”视图中来完成,正如作者在这里建议的那样: http://github.com/flashingpumpkin/django-socialregistration/issues/issue/36/# comment_482137
在您的 urls.py 文件中拦截适当的网址:
您可以将您的用户表单基于socialregistration自己的用户表单,添加代码来填充和保存用户配置文件。
OK, as Tim noted, this particular problem was path related.
Bigger picture, the way to accomplish what I wanted (creating a linked UserProfile when django-socialregistration creates a user) is best done by passing in a custom form into socialregistration's "setup" view, as the author suggested here: http://github.com/flashingpumpkin/django-socialregistration/issues/issue/36/#comment_482137
Intercept the appropriate url in your urls.py file:
You can base your UserForm off socialregistration's own UserForm, adding in code to populate and save the UserProfile.