so I been working on this for a couple of days now and I still dont seem to understand the problem. I am trying to get the username in the url so that you can just look up any user if you type http://127.0.0.1:8000/accounts/profile/username and that users profile shows up. I have looked at other questions but I keep getting this error when I try. If anyone could help me I would be greatly appreciated.
NoReverseMatch at /accounts/profile/admin Reverse for 'viewprofile' with arguments '('',)' not found. 1 pattern(s) tried: ['accounts/profile/(?P[\w.@+-]+)']
views.py
def view_profile(request, username):
username = User.objects.get(username=username)
posts = Post.objects.filter(author = request.user).order_by('-pub_date')
args = {
'user': request.user,
'posts': posts,
}
return render(request, 'accounts/profile.html', args)
in my nav bar: this could be wrong but im sure its right
<li><a href="{% url 'accounts:viewprofile' username%}">Profile</a></li>
urls.py
url(r'^profile/(?P<username>[\w.@+-]+)', views.view_profile, name="viewprofile"),