当前位置: 首页>>代码示例>>Python>>正文


Python Blog.owner方法代码示例

本文整理汇总了Python中blog.models.Blog.owner方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.owner方法的具体用法?Python Blog.owner怎么用?Python Blog.owner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blog.models.Blog的用法示例。


在下文中一共展示了Blog.owner方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import owner [as 别名]
    def post(self, request):
        """
        Crea un user en base a la información POST
        :param request: HttpRequest
        :return: HttpResponse
        """
        success_message = ''

        form = SignupForm(request.POST)
        if form.is_valid():
            user = User()
            user.username = form.cleaned_data.get('usr')
            user.first_name = form.cleaned_data.get('first_name')
            user.last_name = form.cleaned_data.get('last_name')
            user.email = form.cleaned_data.get('email')
            user.set_password(form.cleaned_data.get('password'))
            user.save()

            blog = Blog()
            blog.title = "My first blog"
            blog.owner = user
            blog.save()

            success_message = 'Creado con éxito!'
            success_message += '<a href="{0}">'.format(
                reverse('post_home', args=[])
            )
            success_message += 'go Home!'
            success_message += '</a>'
        context = {
            'form': form,
            'success_message': success_message
        }
        return render(request, 'users/new_user.html', context)
开发者ID:AgDP,项目名称:Django-Wordplease,代码行数:36,代码来源:views.py

示例2: create_blog

# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import owner [as 别名]
def create_blog(request):
	errors = []
	template = "blog/templates/create_blog.html"
	form = CreateBlogForm()
	user = request.user

	if not user.is_authenticated():
		raise Http404

	if request.method == "POST":
		form = CreateBlogForm(request.POST)

		if form.is_valid():
			try:
				data = form.cleaned_data
				_blog = Blog()
				_blog.title = data["title"]
				_blog.owner = user
				_blog.url = data["url"]
				_blog.tagline = data["tagline"]
				_blog.active = True
				_blog.save()
				_blog.contributors.add(user)
				_blog.save()
				return HttpResponseRedirect("/blog/%s/"%user.username)
			except:
				errors.append("Blog URL already taken.")

	return render(request, template, {"errors":errors, "form":form})
开发者ID:ravimalik20,项目名称:blogApp,代码行数:31,代码来源:views.py

示例3: post

# 需要导入模块: from blog.models import Blog [as 别名]
# 或者: from blog.models.Blog import owner [as 别名]
 def post(self, request):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid():
         new_user = serializer.save()
         blog = Blog()
         blog.title = request.data.get("blog")
         blog.owner = new_user
         blog.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:AgDP,项目名称:Django-Wordplease,代码行数:13,代码来源:api.py


注:本文中的blog.models.Blog.owner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。