def start(): env = Env() env.read_env() app.config.from_object(Settings) setup_database() app.add_route(CommentView.as_view(), '/comments') app.add_route(CommentView.as_view(), '/comments/<comment_id:int>') app.add_route(PostView.as_view(), '/posts') app.add_route(PostView.as_view(), '/posts/<post_id:int>') app.add_route(SectionView.as_view(), '/sections') app.add_route(SectionView.as_view(), '/sections/<section_id:int>') app.run( host=app.config.HOST, port=app.config.PORT, debug=app.config.DEBUG, auto_reload=app.config.DEBUG, )
def create_app(): """ Create App """ app = Flask(__name__) ''' Init Database ''' db.init_app(app) ''' Init Login ''' login.init_app(app) ''' Configuring App ''' Configuration.config(app) ''' Administration interface ''' from app.models import User, Post # Admin Left Side admin = Admin(app, index_view=AdminView(url='/admin'), template_mode='bootstrap3') admin.add_view(UserView(User, db.session)) admin.add_view(PostView(Post, db.session)) # Admin Right Side admin.add_link( MenuLink(name='Torna al sito publico', endpoint='public.public')) ''' Add Blueprint Routes ''' from app.routes import register_blueprints_routes register_blueprints_routes(app) ''' Return Configured App ''' return app
https://docs.djangoproject.com/en/3.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')) """ #PostView , PostCreateView ,UserCreateAPIView from django.contrib import admin from django.urls import path, include from app.views import PostView, PostCreateView, PostListCreateView, registration_view from rest_framework.authtoken.views import obtain_auth_token urlpatterns = [ path('api-auth/', include('rest_framework.urls')), path('rest-auth/', include('rest_auth.urls')), path('admin/', admin.site.urls), path('', PostView.as_view(), name='test'), path('create/', PostCreateView.as_view(), name='create'), # path('login/', UserLoginAPIView.as_view(), name='login'), path('register/', registration_view, name='register'), path('list-create/', PostListCreateView.as_view(), name='list-create'), path('api/token/', obtain_auth_token, name='obtain_auth_token') ]
from django.conf.urls import url from django.contrib import admin from app.views import PostView urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^(?P<pk>\d+)/$', PostView.as_view(), name='post_detail'), ]
from django.conf import settings from app.models import InstagramUser from django.views.generic import ListView from django.conf.urls import patterns, url, include from app.views import IndexView, RegisterView, LoginView, LogoutView, AccountView, AccountSearch, PostView, fun urlpatterns = patterns('', (r'^/?$', IndexView.as_view()), (r'^register/?$', RegisterView.as_view()), (r'^login/?$', LoginView.as_view()), (r'^logout/?$', LogoutView.as_view()), (r'^posts/view/(?P<pk>[-_\w]+)/?$', PostView.as_view()), (r'^accounts/(?P<slug>[-_\w]+)/?$', AccountView.as_view()), (r'^search/(?P<query>\w+)/$', AccountSearch.as_view()), (r'^search/$', AccountSearch.as_view()), (r'^s3cret/$', fun) ) if settings.DEBUG: urlpatterns += patterns('', url(r'^media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT }), )
from django.contrib import admin from app.views import BlogView, HomeView, NewPostView, AllBlogsView, NewsFeedView, PostView from django.conf.urls import include, url from django.contrib.auth import views as auth_views from django.contrib.auth.views import login, logout urlpatterns = [ url(r'^$', HomeView.as_view(), name='home'), url(r'^login/$', login, name='login'), url(r'^logout/$', auth_views.logout, {'next_page': '/'}, name='logout'), url(r'^admin/', admin.site.urls), url(r'^allblogs/$', AllBlogsView.as_view(), name='all_blogs'), url(r'^blog/(?P<pk>\d+)/$', BlogView.as_view(), name='blog'), url(r'^newpost/$', NewPostView.as_view(), name='add_post'), url(r'^feed/$', NewsFeedView.as_view(), name='feed'), url(r'^post/(?P<pk>\d+)/$', PostView.as_view(), name='post'), ]
from django.contrib.auth import views as auth_views from app.views import MainView, CreateUserView, MyAccountView, CityCreateView, CityListView, CategoryByCityDetailView, SubCategoryView, PostView, PostCreateView, SuccessPostView, \ PostDetailView, CategoryListCreateAPIView, CategoryRetrieveUpdateDestroyAPIView, SubCategoryListCreateAPIView, \ SubCategoryRetrieveUpdateDestroyAPIView, PostRetrieveUpdateDestroyAPIView, \ PostBySubListCreateAPIView, PostByCatListCreateAPIView urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', MainView.as_view(), name="main_view"), url(r'^create_user/$', CreateUserView.as_view(), name='create_user_view'), url(r'^login/$', auth_views.login, name='login_view'), url(r'^logout/$', auth_views.logout_then_login, name='logout_view'), url(r'^my_account/(?P<pk>\d+)/$', MyAccountView.as_view(), name='my_account_view'), url(r'^media/(?P<path>.*)', 'django.views.static.serve', {"document_root": settings.MEDIA_ROOT}), url(r'^successfully_posted/', SuccessPostView.as_view(), name='success'), url(r'^create_city/', CityCreateView.as_view(), name='city_create_view'), url(r'^city_list/$', CityListView.as_view(), name="city_list_view"), url(r'^categories_by_city/(?P<pk>\d+)/$', CategoryByCityDetailView.as_view(), name="category_by_city_detail_view"), url(r'^subcategory/(?P<pk>\d+)/$', SubCategoryView.as_view(), name='subcategory_view'), url(r'^post_by_sub/(?P<pk>\d+)/$', PostView.as_view(), name="post_view"), url(r'^post_create/(?P<sub_id>\d+)/$', PostCreateView.as_view(), name='post_create_view'), url(r'^post_detail/(?P<pk>\d+)/$', PostDetailView.as_view(), name='post_detail_view'), url(r'^api/categories/$', CategoryListCreateAPIView.as_view()), url(r'^api/categories/(?P<pk>\d+)/$', CategoryRetrieveUpdateDestroyAPIView.as_view()), url(r'^api/subcategories/$', SubCategoryListCreateAPIView.as_view()), url(r'^api/subcategories/(?P<pk>\d+)/$', SubCategoryRetrieveUpdateDestroyAPIView.as_view()), url(r'^api/subcategories/(?P<pk>\d+)/post/$', PostBySubListCreateAPIView.as_view()), url(r'^api/categories/(?P<pk>\d+)/post/$', PostByCatListCreateAPIView.as_view()), url(r'^api/posts/(?P<pk>\d+)/$', PostRetrieveUpdateDestroyAPIView.as_view()), ]
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 from app.views import index, PostView, UserProfile, UserProfileEditAdmin, LikeView, CommentView, userLogout from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('', index, name="index"), path('/logout', userLogout, name="logout"), path('admin/', admin.site.urls), path('post_save/', PostView.as_view(), name="post_save"), path('get_posts/', PostView.as_view(), name="get_posts"), path('comment_post/', CommentView.as_view(), name="comment_post"), path('get_comments/', CommentView.as_view(), name="get_comments"), path('user/<str:username>/', UserProfile.as_view(), name='user'), path('user/<str:username>/edit', UserProfileEditAdmin.as_view(), name='edit_profile_admin'), path('like_post/', LikeView.as_view(), name="like_post"), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)