|
1 |
| -[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fexamples%2Ftree%2Fmain%2Fpython%2Fdjango&demo-title=Django%20%2B%20Vercel&demo-description=Use%20Django%204%20on%20Vercel%20with%20Serverless%20Functions%20using%20the%20Python%20Runtime.&demo-url=https%3A%2F%2Fdjango-template.vercel.app%2F&demo-image=https://assets.vercel.com/image/upload/v1669994241/random/django.png) |
| 1 | +# Python Telegram Bot Vercel |
| 2 | +Telegram bot using based on https://github.com/python-telegram-bot/python-telegram-bot |
2 | 3 |
|
3 |
| -# Django + Vercel |
4 |
| - |
5 |
| -This example shows how to use Django 4 on Vercel with Serverless Functions using the [Python Runtime](https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/python). |
6 |
| - |
7 |
| -## Demo |
8 |
| - |
9 |
| -https://django-template.vercel.app/ |
10 |
| - |
11 |
| -## How it Works |
12 |
| - |
13 |
| -Our Django application, `example` is configured as an installed application in `vercel_app/settings.py`: |
14 |
| - |
15 |
| -```python |
16 |
| -# vercel_app/settings.py |
17 |
| -INSTALLED_APPS = [ |
18 |
| - # ... |
19 |
| - 'example', |
20 |
| -] |
21 |
| -``` |
22 |
| - |
23 |
| -There is a single view which renders the current time in `example/views.py`: |
24 |
| - |
25 |
| -```python |
26 |
| -# example/views.py |
27 |
| -from datetime import datetime |
28 |
| - |
29 |
| -from django.http import HttpResponse |
30 |
| - |
31 |
| - |
32 |
| -def index(request): |
33 |
| - now = datetime.now() |
34 |
| - html = f''' |
35 |
| - <html> |
36 |
| - <body> |
37 |
| - <h1>Hello from Vercel!</h1> |
38 |
| - <p>The current time is { now }.</p> |
39 |
| - </body> |
40 |
| - </html> |
41 |
| - ''' |
42 |
| - return HttpResponse(html) |
43 |
| -``` |
44 |
| - |
45 |
| -This view is exposed a URL through `example/urls.py`: |
46 |
| - |
47 |
| -```python |
48 |
| -# example/urls.py |
49 |
| -from django.urls import path |
50 |
| - |
51 |
| -from example.views import index |
52 |
| - |
53 |
| - |
54 |
| -urlpatterns = [ |
55 |
| - path('', index), |
56 |
| -] |
57 |
| -``` |
58 |
| - |
59 |
| -Finally, it's made accessible to the Django server inside `vercel_app/urls.py`: |
60 |
| - |
61 |
| -```python |
62 |
| -# vercel_app/urls.py |
63 |
| -from django.urls import path, include |
64 |
| - |
65 |
| -urlpatterns = [ |
66 |
| - ... |
67 |
| - path('', include('example.urls')), |
68 |
| -] |
| 4 | +### Environment Variables |
69 | 5 | ```
|
70 |
| - |
71 |
| -This example uses the Web Server Gateway Interface (WSGI) with Django to enable handling requests on Vercel with Serverless Functions. |
72 |
| - |
73 |
| -## Running Locally |
74 |
| - |
75 |
| -```bash |
76 |
| -python manage.py runserver |
| 6 | +webhook = https://{your url}.vercel.app |
| 7 | +TOKEN = Telegram Bot Token |
77 | 8 | ```
|
| 9 | +### Notes |
| 10 | +- Env name is case sensitive |
78 | 11 |
|
79 |
| -Your Django application is now available at `http://localhost:8000`. |
80 |
| - |
81 |
| -## One-Click Deploy |
82 |
| - |
83 |
| -Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=vercel-examples): |
84 |
| - |
85 |
| -[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fexamples%2Ftree%2Fmain%2Fpython%2Fdjango&demo-title=Django%20%2B%20Vercel&demo-description=Use%20Django%204%20on%20Vercel%20with%20Serverless%20Functions%20using%20the%20Python%20Runtime.&demo-url=https%3A%2F%2Fdjango-template.vercel.app%2F&demo-image=https://assets.vercel.com/image/upload/v1669994241/random/django.png) |
0 commit comments