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/1.11/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url from django.contrib import admin from app.views import loggedin_view, logout_view, No_such_user, Auth, Main, User_registered, UserView, TeamView, BetView, registration_form urlpatterns = [ #url(r'^admin/', admin.site.urls), url(r'^$', Main), url(r'^users$', UserView.as_view(), name='users'), url(r'^teams$', TeamView.as_view(), name='teams'), url(r'^bets$', BetView.as_view(), name='bets'), url(r'^registration$', registration_form, name='registration'), url(r'^registered$', User_registered, name='registered'), url(r'^ulogin$', Auth, name='ulogin'), url(r'^nouser$', No_such_user, name='nouser'), url(r'^logout$', logout_view, name='logout'), url(r'^loggedin$', loggedin_view, name='loggedin'), # url('^', include('django.contrib.auth.urls')) ]
app.jinja_env.filters['get_section'] = get_section app.jinja_env.filters['data_format_friendly'] = date_format_friendly app.jinja_env.filters['date_simple'] = date_simple app.jinja_env.filters['thumb_url'] = thumb_url # end register template filters # register app components IndexView.register(app) UserView.register(app) SearchView.register(app) PricingView.register(app) LightboxesView.register(app) ImageDetailsView.register(app) OrderView.register(app) LightboxView.register(app) ProfileView.register(app)
from django.urls import path from app.views import UserView, StudentAPIView, TeacherAPIView urlpatterns = [ path("user_view/", UserView.as_view()), path("user_view/<str:id>/", UserView.as_view()), path("student/", StudentAPIView.as_view()), path("teacher/", TeacherAPIView.as_view()), path("teacher/<str:id>/", TeacherAPIView.as_view()), ]
from django.conf.urls import url, include from app.views import UserView urlpatterns = [url('^$', UserView.as_view(), name="users")]
@app.context_processor def inject_paths(): return dict(product_num = get_product_num(), registereduser_num = get_registereduser_num()) # Create admin admin = flask_admin.Admin( app, 'My Dashboard', base_template='my_master.html', template_mode='bootstrap3', ) # Add model views admin.add_view(MyModelView(Role, db.session, menu_icon_type='fa', menu_icon_value='fa-server', name="Roles")) admin.add_view(UserView(User, db.session, menu_icon_type='fa', menu_icon_value='fa-users', name="Users")) admin.add_view(ProductView(Product, db.session, menu_icon_type='fa', menu_icon_value='fa-users', name="Products")) admin.add_view(RegisteredUserView(RegisteredUser, db.session, menu_icon_type='fa', menu_icon_value='fa-users', name="Registered User")) admin.add_view(CheckoutView(name="Checkout", endpoint='checkout', menu_icon_type='fa', menu_icon_value='fa-connectdevelop',)) admin.add_view(UserRegistrationView(name="User Registration", endpoint='user_registration', menu_icon_type='fa', menu_icon_value='fa-connectdevelop',)) admin.add_view(ObjectDetectionView(name="Object Detection", endpoint='obj_detection', menu_icon_type='fa', menu_icon_value='fa-connectdevelop',)) # define a context processor for merging flask-admin's template context into the # flask-security views. @security.context_processor def security_context_processor(): return dict( admin_base_template=admin.base_template, admin_view=admin.index_view, h=admin_helpers,
# Create dummy secrey key so we can use sessions app.config['SECRET_KEY'] = '123456790' # ==========URLs========== app.add_url_rule('/', view_func=IndexView.as_view('index')) app.add_url_rule('/status/parser', view_func=ParserStatusView.as_view('parser_status')) app.add_url_rule('/status/vk_reminders', view_func=VK_check_status.as_view('vk_reminders')) app.add_url_rule('/status/tg_reminders', view_func=TG_check_status.as_view('tg_reminders')) # ==========Админ панель========== admin = admin.Admin(app, name='Умное расписание ИРНИТУ ', template_mode='bootstrap3') # Добавляем views admin.add_view(UserView(db.users, 'Пользователи Telegram', category='База данных')) admin.add_view(VkUserView(db.VK_users, 'Пользователи Vk', category='База данных')) admin.add_view(InstitutesView(db.institutes, 'Институты', category='База данных')) admin.add_view(AnalyticsView(name='Аналитика', endpoint='analytics')) admin.add_view(StatisticView(db.tg_statistics, 'Статистика Telegram', endpoint='statistics',category='База данных')) admin.add_view(BotSendMessageView(name='Отправка сообщений', endpoint='tg_bot_send_messages', category='Телеграм бот')) admin.add_view(CoursesView(db.courses, 'Курсы', category='База данных')) admin.add_view(GroupsView(db.groups, 'Группы', category='База данных')) admin.add_view(ScheduleView(db.schedule, 'Расписание', category='База данных'))
from django.urls import include, path from app.views import ( ListView, CreateView, DetailView, UserView, UserDetailsView ) from rest_framework.authtoken import views urlpatterns = [ path('list/',ListView.as_view(),name='list'), path('create-bucketlist/',CreateView.as_view(),name='create-bucketlist'), path('<int:pk>/',DetailView.as_view(),name='details'), path('users/', UserView.as_view(), name="users"), path('users/<int:pk>/',UserDetailsView.as_view(), name="user_details"), path('api-auth/', include('rest_framework.urls',namespace='rest_framework')), path('api-token-auth/', views.obtain_auth_token) ]
def user(username): return UserView(username).user_home_page()
from django.contrib import admin from django.urls import path from django.urls import path, include from django.conf.urls.static import static from django.conf import settings from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView from app.views import UserView, APIOverview ''' Use JWT authorization with simplejwt lib Add two endpoints to get access and refresh tokens ''' urlpatterns = [ path('admin/', admin.site.urls), path('', APIOverview.as_view(), name='api_overview'), path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), path('register/', UserView.as_view(), name='register'), path('api/app/', include('app.urls', namespace='app')), path('api/activities/', include('activities.urls', namespace='activities')), path('api/chat/', include('chat.urls', namespace='chat')) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
ROUTER.register(r'choice-disponibilidade-maquina', ChoiceDisponibilidadeMaquinaView) ROUTER.register(r'choice-exame-coleta', ChoiceExameColetaView) ROUTER.register(r'choice-periodo-turno', ChoicePeriodoTurnoView) ROUTER.register(r'choice-status-estadia', ChoiceStatusEstadiaView) ROUTER.register(r'choice-status-manutencao-corretiva', ChoiceStatusManutencaoCorretivaView) ROUTER.register(r'choice-status-paciente', ChoiceStatusPacienteView) ROUTER.register(r'choice-resultado-agua', ChoiceTesteAguaView) ROUTER.register(r'controle-agua', ControleAguaView) ROUTER.register(r'controle-agua/file', FileControleAguaView) ROUTER.register(r'controle-coleta', ControleColetaView) ROUTER.register(r'controle-desinfeccao', ControleDesinfeccaoView) ROUTER.register(r'controle-financeiro', ControleFinanceiroView) ROUTER.register(r'enfermeiro', EnfermeiroView) ROUTER.register(r'erro', ErroView) ROUTER.register(r'estadia', EstadiaView) ROUTER.register(r'manutencao-corretiva', ManutencaoCorretivaView) ROUTER.register(r'manutencao-preventiva', ManutencaoPreventivaView) ROUTER.register(r'maquina', MaquinaView) ROUTER.register(r'paciente', PacienteView) ROUTER.register(r'sala', SalaView) ROUTER.register(r'secao', SecaoView) ROUTER.register(r'tecnico', TecnicoView) urlpatterns = [ url(r'^api/', include(ROUTER.urls)), url(r'^api/report/$', ReportView.as_view(), name='rest_report'), url(r'^api/user/$', UserView.as_view(), name='rest_user_details'), ]
from django.conf.urls import url, include from app.views import UserView, UserListView from rest_framework.documentation import include_docs_urls urlpatterns = [ url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), url( r'^docs/', include_docs_urls(title='My API title', description='API description', public=False)), url(r'^user/$', UserListView.as_view()), url(r'^user/(?P<username>.+)/$', UserView.as_view()), ]
def create_app(path_to_db): app = Flask(__name__) register_routes( app, UserView.as_view("user", user_repository=UserRepository(path_to_db))) return app