Reputation: 1137
I just can't solve my problem, don't see where/what do i wrong. Here is my urls.py:
from accounts.views import AccountList as account_views
urlpatterns = [
re_path(r'^account/(?P<uuid>[\w-]+)/', account_views.account_detail, name='account_detail'),
]
Here is my model
class Account(models.Model):
uuid = ShortUUIDField(unique=True)
name = models.CharField(max_length=80)
desc = models.TextField(blank=True)
address_one = models.CharField(max_length=100)
address_two = models.CharField(max_length=100, blank=True)
city = models.CharField(max_length=50)
state = models.CharField(max_length=2)
phone = models.CharField(max_length=20)
owner = models.ForeignKey(User, on_delete=models.DO_NOTHING,)
created_on = models.DateField(auto_now_add=True)
Here is my view
class AccountList(ListView):
model = Account
@login_required()
def account_detail(request, uuid):
account = Account.objects.get(uuid=uuid)
if account.owner != request.user:
return HttpResponseForbidden()
variables = {
'account': account,
}
return render(request, 'accounts/account_detail.html', variables)
Im tried to render it in my accaunt_detail template with following code:
{% extends 'base.html' %}
{% block content %}
<div id="content-container" class="container p-none">
<div id="ad-container">
<div id="gi-container" class="ad-container">
<div class="row gi-body">
<div class="col-md-9">
<h5 class="gi-sh">Description</h5>
<p>{{ account.desc }}</p>
</div>
<div class="col-md-3">
<h5 class="gi-sh">Address</h5>
<p class="nm">{{ account.address_one }}</p>
<p class="nm">{{ account.address_two }}</p>
<p class="nm">{{ account.city}}, {{ account.state }}</p>
<p class="nm">{{ account.phone}}</p>
</div>
</div>
</div>
</div>
{# List Contacts #}
{# List Communications #}
</div>
{% endblock %}
My base.html
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>CRM Easy</title>
</head>
<body>
<header>
</header>
<div id="site-wrapper">
{% block content %}
if you see this, something is wrong!
{% endblock content %}
</div>
</body>
</html>
I do not get any errors, like everything works fine but the user details are not displayed. I have created ~15 users, so i have users in my database.
Upvotes: 0
Views: 413
Reputation: 600049
This is not at all how class-based views work. You can't define arbitrary methods and point to them from the URL conf; you always need to call the as_view()
in the URL pattern, and the dispatch()
method will call get()
or post()
.
However in this case you are not using any of the features of the class-based view, so there is absolutely no point using one. You should extract your account_detail
method from that class and make it a standalone function, then point your URL pattern directly to that.
Upvotes: 1