def post(request): last_feed = request.POST.get('last_feed') user = request.user csrf_token = (csrf(request)['csrf_token']) feed = Feed() feed.user = user post = request.POST['post'] post = post.strip() if len(post) > 0: feed.post = post[:255] feed.save() html = _html_feeds(last_feed, user, csrf_token) return HttpResponse(html)
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): return render(request, 'authentication/signup.html', {'form': form}) else: username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') User.objects.create_user(username=username, password=password, email=email) user = authenticate(username=username, password=password) login(request, user) welcome_post = '{0} has joined the network.'.format(user.username) feed = Feed(user=user, post=welcome_post) feed.save() return redirect('/') else: return render(request, 'authentication/signup.html', {'form': SignUpForm()})