Olá, estou com esse erro e não estou conseguindo resolver, alguem poderia me ajudar ? Segue o código urls.py
from django.urls import path
from . import views
urlpatterns = [
path('',views.index, name='index'),
path('profiles/<int:profile_id>', views.profileView, name='profile-view'),
path('profiles/<int:profile_id>/invite', views.inviteView, name='invite-view'),
path('invite/<int:invitation_id>/accept', views.acceptView, name='accept-view')
]
views
from django.shortcuts import render, redirect
from profiles.models import Profile,Invitation
#views.py que age como um Controller
# no mundo Django, ou seja, recebe as requisições do
# usuário e devolve uma resposta.
def index(request):
profiles = Profile.objects.all()
return render(request, 'index.html', {'profiles':profiles, 'profile_logged':get_user_id(request)})
def profileView(request,profile_id):
profile = Profile.objects.get(id=profile_id)
profile_logged = get_user_id(request)
is_contact = profile in profile_logged.contacts.all()
return render(request, 'profile.html',{"profile":profile,'profile_logged':get_user_id(request)})
def get_user_id(request):
return Profile.objects.get(id=4)
def inviteView(request, profile_id):
profile_to_invite = Profile.objects.get(id=profile_id) # get's the profile object
profile_logged = get_user_id(request)
profile_logged.invite(profile_to_invite)
return redirect('index')
def acceptView(request, invitation_id):
invitation = Invitation.objects.get(id=invitation_id)
invitation.accept()
return redirect('index')
Index
{% extends "base.html" %}
{% block content %}
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Users</strong>
</div>
{% if profiles %}
<ul>
{% for profile in profiles %}
<li>
<a href="{% url 'profile-view' profile.id%}">{{ profile.name }}</a> / {{ profile.email }}
</li>
{% endfor %}
</ul>
{% else %}
<p>No users found</p>
{% endif %}
</div>
<div class="panel panel-default">
{% with total_invites=profile_logged.invitations_received.count%}
{% if total_invites %}
<div class="panel-heading">
<strong>You have {{total_invites}} invite{{total_invites|pluralize}} from your network</strong>
</div>
<ul class="list-group">
{% for invite in profile_logged.invitations_received.all %}
<li class="list-group-item">
{{ invite.sender.name }}
<a href="{% url 'accept-view' invitation.id %}" class="pull-right">accept</a>
</li>
{% endfor %}
</ul>
{% else %}
<div class="panel-body">
<p> No invitations so far :(</p>
</div>
{% endif %}
</div>
{% endwith %}
</div>
<div class="panel panel-default">
{% with total_contacts=profile_logged.contacts.count %}
{% if total_contacts %}
<div class="panel-heading">
<strong>You have {{total_contacts}} contact{{ total_contacts|pluralize }}</strong>
</div>
<ul class="list-group">
{% for contact in profile_logged.contact.all %}
<a href="{% url 'profile-view' contact.id %}" class="list-group-item">{{ contact.name }} // {{ contact.email }}</a>
{% endfor %}
</ul>
{% else %}
<div class="panel-body">
<p>You have no contacts:(</p>
</div>
{% endif %}
{% endwith %}
</div>
</div>
{% endblock %}
Obrigado pela atenção