Skip to content

Instantly share code, notes, and snippets.

@cjadeveloper
Created November 7, 2018 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjadeveloper/0792cd5ef40295bf2381f9583ef29483 to your computer and use it in GitHub Desktop.
Save cjadeveloper/0792cd5ef40295bf2381f9583ef29483 to your computer and use it in GitHub Desktop.
Maestro Django2 - Clase 82 - Profiles
###
## profiles/urls.py
#
from django.urls import path
from .views import ProfileListView, ProfileDetailView
profiles_patterns = ([
path('', ProfileListView.as_view(), name='list'),
path('<username>/', ProfileDetailView.as_view(), name='detail'),
], 'profiles')
###
## profiles/views.py
#
from django.shortcuts import get_object_or_404
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from registration.models import Profile
class ProfileListView(ListView):
model: Profile
class ProfileDetailView(DetailView):
model: Profile
def get_object(self):
return get_object_or_404(Profile, user__username=self.kwargs['username'])
###
## webplayground/urls.py
#
"""webplayground URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from pages.urls import pages_patterns
from profiles.urls import profiles_patterns
from django.conf import settings
urlpatterns = [
path('', include('core.urls')),
path('pages/', include(pages_patterns)),
path('profiles/', include(profiles_patterns)),
path('admin/', admin.site.urls),
# Paths de Auth
path('accounts/', include('django.contrib.auth.urls')),
path('accounts/', include('registration.urls')),
]
if settings.DEBUG:
from django.conf.urls.static import static
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment