Making a Twitter clone in Django, having trouble with displaying the right user when displaying tweets
<p>I have user registration. Whenever I log in as a certain user, all the tweets are said to be tweeted by that user, even if it wasn't.</p>

<p><strong>forms.py</strong></p>

<pre><code>from django.contrib.auth.models import User
from django import forms

class UserForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput)

class Meta:
    model = User
    fields = ['username', 'password', 'email']
</code></pre>

<p><strong>models.py</strong></p>

<pre><code>from django.db import models
from django.core.urlresolvers import reverse
from django.utils import timezone
from django.contrib.auth.models import User

class Howl(models.Model):
    author = models.ForeignKey('auth.user', null=True)
    content = models.CharField(max_length=150)
    published_date = models.DateTimeField(default=timezone.now)
    like_count = models.IntegerField(default=0)
    rehowl_count = models.IntegerField(default=0)

    def get_absolute_url(self):
        return reverse('howl:index')

    def __str__(self):
        return self.content 
</code></pre>

<p><strong>index.html</strong></p>

<pre><code>{% block content %}
&lt;h2&gt;Index.html timeline!&lt;/h2&gt;
{% for howl in howls %}
    &lt;div class="howl"&gt;
        &lt;h2&gt;&lt;strong&gt;{{user.username}}&lt;/strong&gt;&lt;/h2&gt;
        &lt;p class="lead"&gt;{{howl.content}} - {{howl.published_date}}&lt;/p&gt;
        &lt;span&gt;Rehowls: {{howl.rehowl_count}}, Likes: {{howl.like_count}}&lt;/span&gt;
    &lt;/div&gt;&lt;!--howl--&gt;
{% endfor%}
{% endblock %}
</code></pre>

<p><strong>views.py</strong></p>

<pre><code>from django.shortcuts import render, redirect
from django.views import generic
from django.views.generic import View 
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from .models import Howl
from .forms import UserForm
from django.contrib.auth import authenticate, login

class IndexView(generic.ListView):
    template_name = 'howl/index.html'
    context_object_name = 'howls'

    def get_queryset(self):
        return Howl.objects.all()

class HowlCreate(CreateView):
    model = Howl
    fields = ['content']

class UserFormView(View):
    form_class = UserForm
    template_name = 'howl/registration_form.html'

    def get(self, request):
        form = self.form_class(None)
        return render(request, self.template_name, {'form': form})

    def post(self, request):
        form = self.form_class(request.POST)

        if form.is_valid():
            user = form.save(commit=False)

            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user.set_password(password)
            user.save()

            user = authenticate(username=username, password=password)

            if user is not None:

                if user.is_active:
                    login(request, user)
                    return redirect('howl:index')
</code></pre>

<p>I know that using user.username in index.html is the problem. It shows the current user logged in as the author of these tweets. How do I make it so that it displays the rightful owner of a tweet? </p>

<p>On my HowlCreate view, I didn't set the author to the howl. I only set the content. </p>

<pre><code>class HowlCreate(CreateView):
    model = Howl
    fields = ['content']

    # This sets up the author 
    def form_valid(self, form):
        instance = form.save(commit=False)
        instance.author = self.request.user # set current user as author
        instance.save()

        return HttpResponseRedirect(self.get_success_url())
</code></pre>

python django