from django.contrib import admin from django.conf import settings from django.conf.urls.static import static from accounts.views import UserRegisterView from hashtags.api.views import TagTweetAPIView from hashtags.views import HashTagView from tweets.api.views import SearchTweetAPIView from tweets.views import TweetListView from .views import home, SearchView urlpatterns = [ url(r'^admin/', admin.site.urls), #admin/ url(r'^$', TweetListView.as_view(), name='home'), #/ url(r'^search/$', SearchView.as_view(), name='search'), #/ url(r'^tags/(?P<hashtag>.*)/$', HashTagView.as_view(), name='hashtag'), url(r'^tweet/', include('tweets.urls', namespace='tweet')), url(r'^api/tags/(?P<hashtag>.*)/$', TagTweetAPIView.as_view(), name='tag-tweet-api'), url(r'^api/search/$', SearchTweetAPIView.as_view(), name='search-api'), url(r'^api/tweet/', include('tweets.api.urls', namespace='tweet-api')), url(r'^api/', include('accounts.api.urls', namespace='profiles-api')), url(r'^register/$', UserRegisterView.as_view(), name='register'), #/ url(r'^', include('django.contrib.auth.urls')), url(r'^', include('accounts.urls', namespace='profiles')), ] if settings.DEBUG: urlpatterns += (static(settings.STATIC_URL, document_root=settings.STATIC_ROOT))
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 django.conf import settings from django.conf.urls.static import static from tweets.views import TweetListView from hashtags.views import HashTagView from . import views urlpatterns = [ path('admin/', admin.site.urls), path('', TweetListView.as_view(), name='home'), path('tags/<hashtag>/', HashTagView.as_view(), name='hashtag'), path('tweets/', include('tweets.urls', namespace="tweets")), path('api/tweets/', include('tweets.api.urls', namespace="tweets-api")), path('', include('accounts.urls', namespace="profiles")), ] if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.conf.urls.static import static from accounts.views import UserRegisterView from hashtags.api.views import TagTweetAPIView from hashtags.views import HashTagView from tweets.views import TweetListView from tweets.api.views import SearchTweetAPIView from .views import SearchView urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', TweetListView.as_view(), name='home'), url(r'^search/$', SearchView.as_view(), name='search'), url(r'^tweets/', include('tweets.urls', namespace='tweets')), url(r'^tags/(?P<hashtag>.*)/$', HashTagView.as_view(), name='hashtag'), url(r'^api/tweets/', include('tweets.api.urls', namespace='tweets-api')), url(r'^api/', include('accounts.api.urls', namespace='profiles-api')), url(r'^api/tags/(?P<hashtag>.*)/$', TagTweetAPIView.as_view(), name='tag-tweet-api'), url(r'^api/search/$', SearchTweetAPIView.as_view(), name='search-api'), url(r'^register/$', UserRegisterView.as_view(), name='register'), url(r'^', include('django.contrib.auth.urls')), url(r'^', include('accounts.urls', namespace='profiles')), ] if settings.DEBUG: urlpatterns += (static(settings.STATIC_URL, document_root=settings.STATIC_ROOT))
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 django.conf import settings from django.conf.urls.static import static from hashtags.views import HashTagView from .views import home from tweets.views import TweetListView urlpatterns = [ path('admin/', admin.site.urls), path('', TweetListView.as_view(), name='home-view'), path('tags/<str:hashtag>/', HashTagView.as_view(), name='hashtag-view'), path('tweet/', include(('tweets.urls', 'tweets'), namespace='tweet')), path('', include(('accounts.urls', 'profiles'), namespace='profile')), path('api/tweet/', include(('tweets.api.urls', 'tweets'), namespace='tweet-api')), ] if settings.DEBUG: urlpatterns += (static(settings.STATIC_URL, document_root=settings.STATIC_ROOT))
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.conf import settings from django.conf.urls.static import static from django.contrib import admin from django.urls import path, include from django.contrib.auth.decorators import login_required from hashtags.views import HashTagView urlpatterns = [ path('admin/', admin.site.urls), path('', include('user_registration.urls')), path('post/', include('posts.urls', namespace='post')), path('tags/<hashtag>/', login_required(HashTagView.as_view()), name='post-hashtags'), path('api-auth/', include('rest_framework.urls')), path('post/api/', include('posts.api.urls', namespace='post-api')), path('profile/api/', include('user_registration.api.urls', namespace='user-api')), path('tags/<hashtag>/api/', include('hashtags.api.urls', namespace='hashtag-api')) ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from django.urls import path, include from django.contrib.auth.decorators import login_required from hashtags.views import HashTagView from oauth2_provider.views.generic import ProtectedResourceView from django.http import HttpResponse,JsonResponse from rest_framework.views import APIView class ApiEndpoint(APIView): def get(self, request, *args, **kwargs): print(request.user.username) return JsonResponse({'email':request.user.email,'first_name':request.user.get_short_name(),'last_name':request.user.last_name}) if request.user.is_authenticated: return HttpResponse('Hello there! You are acting on behalf of '+str(request.user)) else: return HttpResponse('Hello! I do not recognize you\n') urlpatterns = [ path('admin/', admin.site.urls), path('', include('user_registration.urls')), path('post/', include('posts.urls', namespace='post')), path('tags/<hashtag>/', login_required(HashTagView.as_view()), name='post-hashtags'), path('api-auth/', include('rest_framework.urls')), path('post/api/', include('posts.api.urls', namespace='post-api')), path('profile/api/', include('user_registration.api.urls', namespace='user-api')), path('tags/<hashtag>/api/', include('hashtags.api.urls', namespace='hashtag-api')), path('o/', include('oauth2_provider.urls', namespace='oauth2_provider')), path('api/hello/', ApiEndpoint.as_view()), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.2/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.conf import settings from django.conf.urls.static import static from django.contrib import admin from django.urls import path, include from hashtags.views import HashTagView urlpatterns = [ path('accounts/', include("accounts.urls")), path('admin/', admin.site.urls), path('', include("posts.urls")), path('search/', include("search.urls")), path("tag/<str:hashtag>/", HashTagView.as_view(), name="hashtag"), ] if settings.DEBUG: urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
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 from django.conf import settings from django.conf.urls.static import static from django.conf.urls import include from .views import index from tweets.views import TweetListView from hashtags.views import HashTagView urlpatterns = [ path('', TweetListView.as_view(), name="index"), path('admin/', admin.site.urls), path('tags/<path:hashtag>/', HashTagView.as_view(), name="hashtag"), # path('profiles/', include('accounts.urls', namespace='profiles')), path('tweet/', include('tweets.urls', namespace='tweets')), path('api/tweet/', include('tweets.api.urls', namespace='tweets-api')), path('api/', include('accounts.api.urls', namespace='profiles-api')), path('', include('accounts.urls', namespace='profiles')), ] if settings.DEBUG: urlpatterns += (static(settings.STATIC_URL, document_root=settings.STATIC_ROOT))