Getting a Current user Id

Hello I am trying to get the current login user as I would like to have it as my author name in the blog post. Right now i am using js to get a user id.

add_post.html

<script>
    var name = "{{user.id}}";
    document.getElementById("current_user").value = name;
</script>

forms.py

class PostForms(forms.ModelForm):
    class Meta:
        model = Post
        fields = ('title', 'author', 'category','snippet', 'body')

        widgets = {
            'title' : forms.TextInput(attrs={'class':'form-control'}),
            'author' : forms.TextInput(attrs={'class':'form-control', 'value': '','id':'current_user','type':'hidden'}),

Is their a better way to achieve this ?

The request object contains a reference to the current user. See Using the Django authentication system | Django documentation | Django for details.