diff --git a/django_telegrambot/urls.py b/django_telegrambot/urls.py index f348adc..ed07f92 100644 --- a/django_telegrambot/urls.py +++ b/django_telegrambot/urls.py @@ -1,15 +1,15 @@ -from django.conf.urls import url +from django.urls import path, re_path from . import views from django.conf import settings -webhook_base = settings.DJANGO_TELEGRAMBOT.get('WEBHOOK_PREFIX','/') +webhook_base = settings.DJANGO_TELEGRAMBOT.get('WEBHOOK_PREFIX', '') if webhook_base.startswith("/"): webhook_base = webhook_base[1:] -if not webhook_base.endswith("/"): +if webhook_base is not '' and not webhook_base.endswith("/"): webhook_base += "/" urlpatterns = [ - url(r'admin/django-telegrambot/$', views.home, name='django-telegrambot'), - url(r'{}(?P.+?)/$'.format(webhook_base), views.webhook, name='webhook'), + path('admin/django-telegrambot/', views.home, name='django-telegrambot'), + re_path('{}(?P[-_:a-zA-Z0-9]+)/'.format(webhook_base), views.webhook, name='webhook'), ] diff --git a/django_telegrambot/views.py b/django_telegrambot/views.py index 37d76e7..a0e288a 100644 --- a/django_telegrambot/views.py +++ b/django_telegrambot/views.py @@ -20,7 +20,7 @@ @staff_member_required def home(request): bot_list = DjangoTelegramBot.bots - context = {'bot_list': bot_list, 'update_mode':settings.DJANGO_TELEGRAMBOT.get('MODE', 'WEBHOOK')} + context = {'bot_list': bot_list, 'update_mode': settings.DJANGO_TELEGRAMBOT.get('MODE', 'WEBHOOK')} return render(request, 'django_telegrambot/index.html', context) @@ -30,14 +30,14 @@ def webhook (request, bot_token): #verifico la validità del token bot = DjangoTelegramBot.getBot(bot_id=bot_token, safe=False) if bot is None: - logger.warn('Request for not found token : {}'.format(bot_token)) + logger.warning('Request for not found token : {}'.format(bot_token)) return JsonResponse({}) try: data = json.loads(request.body.decode("utf-8")) except: - logger.warn('Telegram bot <{}> receive invalid request : {}'.format(bot.username, repr(request))) + logger.warning('Telegram bot <{}> receive invalid request : {}'.format(bot.username, repr(request))) return JsonResponse({}) dispatcher = DjangoTelegramBot.getDispatcher(bot_token, safe=False) @@ -51,7 +51,7 @@ def webhook (request, bot_token): logger.debug('Bot <{}> : Processed update {}'.format(bot.username, update)) # Dispatch any errors except TelegramError as te: - logger.warn("Bot <{}> : Error was raised while processing Update.".format(bot.username)) + logger.warning("Bot <{}> : Error was raised while processing Update.".format(bot.username)) dispatcher.dispatchError(update, te) # All other errors should not stop the thread, just print them diff --git a/sampleproject/bot/urls.py b/sampleproject/bot/urls.py index c714da7..b1782ac 100644 --- a/sampleproject/bot/urls.py +++ b/sampleproject/bot/urls.py @@ -1,7 +1,7 @@ -from django.conf.urls import url +from django.urls import path from . import views urlpatterns = [ - url(r'^$', views.index, name='index'), + path('', views.index, name='index'), ] diff --git a/sampleproject/manage.py b/sampleproject/manage.py index b20ac34..f5ce374 100755 --- a/sampleproject/manage.py +++ b/sampleproject/manage.py @@ -6,7 +6,7 @@ sys.path.append(path) if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sampleproject.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sampleproject.local_settings") try: from django.core.management import execute_from_command_line except ImportError: diff --git a/sampleproject/sampleproject/local_settings.sample.py b/sampleproject/sampleproject/local_settings.sample.py index 6ddf1c5..1fab894 100644 --- a/sampleproject/sampleproject/local_settings.sample.py +++ b/sampleproject/sampleproject/local_settings.sample.py @@ -1,4 +1,5 @@ #settings.py +from .settings import * DJANGO_TELEGRAMBOT = { 'MODE' : 'WEBHOOK', #(Optional [str]) # The default value is WEBHOOK, diff --git a/sampleproject/sampleproject/urls.py b/sampleproject/sampleproject/urls.py index 4befeeb..78e6306 100644 --- a/sampleproject/sampleproject/urls.py +++ b/sampleproject/sampleproject/urls.py @@ -13,11 +13,11 @@ 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, include +from django.urls import re_path, path, include from django.contrib import admin urlpatterns = [ - url(r'^admin/', admin.site.urls), - url(r'^', include('django_telegrambot.urls')), - url(r'^$', include('bot.urls')), + path('admin/', admin.site.urls), + path('', include('django_telegrambot.urls')), + path('', include('bot.urls')), ]