Profiles

Models

Database models for the profiles app.

class profiles.models.Profile(*args, **kwargs)

Stores a single profile entry.

Related to auth.User.

Parameters:
  • user – The user.

  • favorite_city – The user’s favorite city.

Class definition

in models.py
class Profile(models.Model):
    """Stores a single profile entry.

    Related to :class:`auth.User`.

    :param user: The user.
    :param favorite_city: The user's favorite city.
    """
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    favorite_city = models.CharField(max_length=64, blank=True)

    def __str__(self):
        return self.user.username

Views

Views for profiles app.

profiles.views.index(request)

Display a list of profiles.Profile.

Template: profiles/index.html

profiles.views.profile(request, username)

Display an individual profiles.Profile.

Template: profiles/profile.html

URLs

URL Configuration for profiles app.

in urls.py
urlpatterns = [
    path('', views.index, name='index'),
    path('<str:username>/', views.profile, name='profile'),
]