我正在Django Rest Framework中构建一个项目,用户可以登录查看他们的酒窖.我的ModelViewSets工作得很好,突然间我得到了这个令人沮丧的错误:
无法使用视图名称"user-detail"解析超链接关系的URL.您可能未能在API中包含相关模型,或者未
lookup_field在此字段上错误地配置属性.
追溯显示:
[12/Dec/2013 18:35:29] "GET /bottles/ HTTP/1.1" 500 76677
Internal Server Error: /bottles/
Traceback (most recent call last):
File "/Users/bpipat/.virtualenvs/usertest2/lib/python2.7/site-packages/django/core/handlers/base.py", line 114, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/bpipat/.virtualenvs/usertest2/lib/python2.7/site-packages/rest_framework/viewsets.py", line 78, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/bpipat/.virtualenvs/usertest2/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 57, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/bpipat/.virtualenvs/usertest2/lib/python2.7/site-packages/rest_framework/views.py", line 399, in dispatch
response = self.handle_exception(exc)
File "/Users/bpipat/.virtualenvs/usertest2/lib/python2.7/site-packages/rest_framework/views.py", line 396, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/bpipat/.virtualenvs/usertest2/lib/python2.7/site-packages/rest_framework/mixins.py", line 96, in list
return …Run Code Online (Sandbox Code Playgroud) 我正在开发一个webapp,用户可以登录以查看他们的在线酒窖.
我有Django REST模型设置,以及Angular中的前端设计,但我无法将各个部分放在一起,我的主要问题是用户身份验证.
我在这里阅读了很多帖子和各种教程,但我似乎无法找到一步步实现身份验证的方法:
根据我的理解,Angular在URL上发出POST请求,其中DRF验证用户名和密码是否匹配并返回令牌或其他身份证明.
我觉得我很接近,但我需要更全面地了解这是如何将各个部分组合在一起的.
提前致谢
python authentication django angularjs django-rest-framework
我正在尝试从Django Rest Framework返回一个HttpResponse,包括来自2个链接模型的数据.模型是:
class Wine(models.Model):
color = models.CharField(max_length=100, blank=True)
country = models.CharField(max_length=100, blank=True)
region = models.CharField(max_length=100, blank=True)
appellation = models.CharField(max_length=100, blank=True)
class Bottle(models.Model):
wine = models.ForeignKey(Wine, null=False)
user = models.ForeignKey(User, null=False, related_name='bottles')
Run Code Online (Sandbox Code Playgroud)
我想要一个Bottle模型的序列化器,其中包含来自相关Wine的信息.
我试过了:
class BottleSerializer(serializers.HyperlinkedModelSerializer):
wine = serializers.RelatedField(source='wine')
class Meta:
model = Bottle
fields = ('url', 'wine.color', 'wine.country', 'user', 'date_rated', 'rating', 'comment', 'get_more')
Run Code Online (Sandbox Code Playgroud)
这不起作用.
任何想法我怎么能这样做?
谢谢 :)
python django serialization foreign-keys django-rest-framework
我正在尝试使用Mandrill模板发送订单跟踪电子邮件.
使用mc:edit适用于简单的文本 <span mc:edit="ship_id">ship_id</span><br>
我想知道是否有办法在变量即tracking_url中传递href链接
<a class="mcnButton " title="Track order" href=tracking_url target="_blank" style="font-weight: bold;text-align: center;">Track Order</a>
我正在使用Djrill for Django,这是迄今为止发送电子邮件的代码,我想将tracking_url添加为template_content变量或类似的东西
msg = EmailMessage(subject="Track your order", from_email="admin@example.com", to=[user.email])
msg.template_name = "order-sent"
msg.template_content = {'order_id' : order_id, 'order_date' : order_date, 'order_type' : order_type, 'first_name' : user.first_name, 'last_name' : user.last_name, 'phone' : user.info.phone,
'd_street' : d.street, 'd_zipcode' : d.zipcode, 'd_city' : d.city, 'd_country' : d.country}
msg.send()
Run Code Online (Sandbox Code Playgroud)
似乎可以使用AddGlobalVariable方法(在这里阅读),但我无法弄清楚如何使用它.