Created
November 7, 2018 03:44
-
-
Save cjadeveloper/0792cd5ef40295bf2381f9583ef29483 to your computer and use it in GitHub Desktop.
Maestro Django2 - Clase 82 - Profiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
## 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
## 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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
## 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