{"id":18727,"date":"2026-11-19T00:11:19","date_gmt":"2026-11-18T18:41:19","guid":{"rendered":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/"},"modified":"2026-11-19T00:51:02","modified_gmt":"2026-11-18T19:21:02","slug":"otp-login-django-fast2sms","status":"publish","type":"post","link":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/","title":{"rendered":"Django OTP login with Fast2SMS Smart OTP (starter kit)"},"content":{"rendered":"<p>This guide shows you how to add a Django OTP login page to your project with Fast2SMS Smart OTP. Our starter kit is a drop-in Django app called <code>fast2sms_otp<\/code>. You add it to <code>INSTALLED_APPS<\/code>, mount its URLs and set two values, and users can log in with a code sent to their mobile by SMS or WhatsApp.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Add OTP login to your Django app<\/strong><p>Create a Smart OTP template, copy your OTP ID and start sending codes on SMS and WhatsApp.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>What you build<\/h2>\n<p>A login page that works like this:<\/p>\n<ol>\n<li>The user types a mobile number and clicks <strong>Send OTP<\/strong>. Fast2SMS creates the code and sends it.<\/li>\n<li>The user types the code and clicks <strong>Verify<\/strong>. Fast2SMS checks it, and your app logs the user in.<\/li>\n<li>A <strong>Resend code<\/strong> button works after a short wait (30 seconds by default).<\/li>\n<\/ol>\n<p>The kit uses <strong>Smart OTP<\/strong>, our recommended way to send OTPs. An OTP template sends on SMS or WhatsApp, with optional fallback to the other channel, on a priority route. Fast2SMS creates, stores and checks the code, so your app does not keep any OTP itself.<\/p>\n<p class=\"f2s-kit-wrap\"><a class=\"f2s-kit\" href=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/fast2sms-smart-otp-python-django.zip\" download><svg class=\"f2s-kit__icon\" width=\"28\" height=\"28\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#7F56D9\" d=\"M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z\"\/><path fill=\"#FFFFFF\" d=\"M14 2v6h6\"\/><path fill=\"#FFFFFF\" d=\"M9 6h2v2H9zm2 2h2v2h-2zM9 10h2v2H9zm2 2h2v2h-2zm-2 2h4v4H9z\"\/><rect x=\"10\" y=\"15.4\" width=\"2\" height=\"1.6\" fill=\"#7F56D9\"\/><\/svg><span class=\"f2s-kit__text\"><strong>Download the ready-made starter kit (zip)<\/strong><span class=\"f2s-kit__meta\">fast2sms-smart-otp-python-django.zip &middot; 24 KB<\/span><\/span><span class=\"f2s-kit__btn\">Download .zip<\/span><\/a><\/p>\n<div class=\"f2s-note\">We tested this kit with Python 3.12.10 and Django 6.1.3 in a fresh project that mounted the app at <code>\/otp\/<\/code>, against a local copy of the Fast2SMS API (a mock server, so no real SMS was sent): all 23 client tests and the full 16-step browser test passed.<\/div>\n<h2>Before you start<\/h2>\n<ul>\n<li>A Fast2SMS account with wallet balance. Every OTP you send is charged.<\/li>\n<li>For SMS OTP: an approved DLT entity, sender ID and OTP content template in <strong>DLT Manager<\/strong>. For WhatsApp OTP: a connected WhatsApp number with an approved authentication (or utility) template.<\/li>\n<li>A Django 4.2 or newer project with sessions and CSRF turned on. A project made with <code>django-admin startproject<\/code> has both. No new Python packages are needed.<\/li>\n<\/ul>\n<h2>Set up Django OTP login in 5 steps<\/h2>\n<ol class=\"f2s-steps\">\n<li>\n<h3>Create a Smart OTP template<\/h3>\n<p>In the panel, open <strong>Smart OTP<\/strong> &gt; <strong>OTP Template List<\/strong> and click <strong>Add OTP Template<\/strong>. On the <strong>SMS Channel<\/strong> tab, pick your entity, sender and approved DLT OTP template, then click the variable button that holds the code and click <strong>Assign OTP Template<\/strong>. For WhatsApp, use the <strong>WhatsApp Channel<\/strong> tab. You can also tick <strong>SET FALLBACK TEMPLATE<\/strong> to add the other channel as a fallback.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-4-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Add OTP Template window on the SMS Channel tab with entity, sender and DLT template selected and the variable buttons below the preview\"><figcaption>Pick the entity, sender and DLT template, then choose which variable holds the OTP.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Copy the OTP ID<\/h3>\n<p>Your new template shows as a card in the <strong>OTP Template List<\/strong>. Copy its <strong>OTP ID<\/strong> with the copy icon. It is 10 characters long, for example <code>a1b2c3d4e5<\/code>.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-template-list-hd-20-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"Smart OTP Template list with WhatsApp and SMS template cards, each showing its OTP ID with a copy icon\"><figcaption>Each card shows the OTP ID you put in your .env file.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Copy your API key<\/h3>\n<p>In the left menu under <strong>Utility<\/strong>, click <strong>API Key<\/strong>. Click <strong>View<\/strong> to see the full <strong>Authorization Key<\/strong> (the panel asks for an OTP sent to your registered mobile first) and copy it. Check that <strong>API Access<\/strong> is switched on.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/api-key-hd-23-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"API Key page with the masked Authorization Key, View and Reset buttons and the API Access switch turned on\"><figcaption>Copy the Authorization Key. API Access must be on.<\/figcaption><\/figure>\n<\/li>\n<li>\n<h3>Add the app and your keys<\/h3>\n<p>Copy the <code>fast2sms_otp<\/code> folder next to <code>manage.py<\/code>. Add <code>\"fast2sms_otp\"<\/code> to <code>INSTALLED_APPS<\/code> in <code>settings.py<\/code>, and mount the URLs in your project&#8217;s <code>urls.py<\/code>:<\/p>\n<pre><code class=\"language-python\">from django.urls import include, path\n\nurlpatterns = [\n    # ... your other URLs\n    path(\"otp\/\", include(\"fast2sms_otp.urls\")),\n]<\/code><\/pre>\n<p>Copy <code>.env.example<\/code> to <code>.env<\/code> next to <code>manage.py<\/code> and set your values (or set them as environment variables):<\/p>\n<pre><code class=\"language-bash\">FAST2SMS_API_KEY=YOUR_API_KEY\nFAST2SMS_OTP_ID=a1b2c3d4e5\nOTP_RESEND_WAIT_SECONDS=30<\/code><\/pre>\n<p>Never commit <code>.env<\/code> to git; make sure your <code>.gitignore<\/code> lists it.<\/p>\n<\/li>\n<li>\n<h3>Run it and log in<\/h3>\n<p>Create the session table if you have not done it yet, then start the server:<\/p>\n<pre><code class=\"language-bash\">python manage.py migrate\npython manage.py runserver<\/code><\/pre>\n<p>Open <code>http:\/\/127.0.0.1:8000\/otp\/<\/code>, type your own mobile number and click <strong>Send OTP<\/strong>, then type the code and click <strong>Verify<\/strong>.<\/p>\n<\/li>\n<\/ol>\n<h2>How send, verify and resend work in the Django kit<\/h2>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Step<\/th>\n<th>Your app calls<\/th>\n<th>Fast2SMS endpoint<\/th>\n<th>Charged?<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Send<\/td>\n<td><code>client.send(mobile, otp_id)<\/code><\/td>\n<td><code>POST \/dev\/otp\/send<\/code><\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Verify<\/td>\n<td><code>client.verify(mobile, code)<\/code><\/td>\n<td><code>POST \/dev\/otp\/verify<\/code><\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>Resend<\/td>\n<td><code>client.resend_or_send(mobile, otp_id)<\/code><\/td>\n<td><code>POST \/dev\/otp\/resend<\/code>, falls back to send<\/td>\n<td>Yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>The client is <code>fast2sms_otp\/fast2sms_smart_otp.py<\/code> and uses only the standard library. The views are in <code>views.py<\/code>. To see the kit&#8217;s log lines, add a logger named <code>fast2sms<\/code> to <code>LOGGING<\/code> in <code>settings.py<\/code>.<\/p>\n<h3>Send<\/h3>\n<p>The kit first cleans the number, so <code>+91 98765-43210<\/code> becomes <code>9876543210<\/code>. Anything that is not a 10-digit Indian mobile starting with 6 to 9 is refused before any API call, so it costs nothing. Then it sends the mobile and your OTP ID. Fast2SMS makes a 6-digit code that is valid for 15 minutes, unless you pass <code>otp_length<\/code> (4 to 10) or <code>otp_expiry<\/code> (1 to 10080 minutes).<\/p>\n<p>&#8220;OTP sent successfully&#8221; means Fast2SMS accepted the request. It does not mean the phone has received it. Delivery shows in <strong>Smart OTP<\/strong> &gt; <strong>Delivery Report<\/strong> and in the OTP webhook.<\/p>\n<h3>Verify<\/h3>\n<p>Verify needs only the mobile and the code the user typed, no OTP ID. Fast2SMS checks the latest unverified code for that mobile. Sending a new OTP cancels the older codes, so only the newest one works. The result is one of <code>verified<\/code>, <code>invalid<\/code> (wrong code, one try used), <code>expired<\/code>, <code>max_attempts<\/code> or <code>not_found<\/code>.<\/p>\n<p>This is the verify view from <code>views.py<\/code>. On success it cycles the session key:<\/p>\n<pre><code class=\"language-python\">r = client().verify(mobile, otp)\nif r.ok:\n    # Logged in. A new session key stops session fixation.\n    # In a real project: find or create the User for this mobile and call django.contrib.auth.login().\n    s.cycle_key()\n    for k in (PENDING, SENT_AT, NEED_NEW):\n        s.pop(k, None)\n    s[USER] = mobile\nelse:\n    s[NEED_NEW] = r.reason in (\"expired\", \"max_attempts\", \"not_found\")\n    flash(request, \"error\", VERIFY_MESSAGES.get(r.reason, \"Could not check the code: \" + r.message))<\/code><\/pre>\n<h3>Resend<\/h3>\n<p>Resend sends the same code again and is charged like a new send. It works only within 10 minutes of the last send, and Fast2SMS allows at most 5 sends to one number in those 10 minutes, counting the first. So a user gets up to 4 resends. When there is nothing to resend (never sent, already verified, or the 10 minutes are over), the kit sends a new code instead:<\/p>\n<pre><code class=\"language-python\">def resend_or_send(self, mobile: str, otp_id: str, **send_options) -&gt; Result:\n    \"\"\"Resend; if there is nothing to resend (none, verified or window over), send a new OTP instead.\"\"\"\n    r = self.resend(mobile)\n    if r.reason in (\"no_previous\", \"already_verified\", \"window_expired\"):\n        r = self.send(mobile, otp_id, **send_options)\n        r.sent_new = True\n    return r<\/code><\/pre>\n<p>The <a href=\"\/help\/api-key-find-reset\/\">API key<\/a> goes in the <code>authorization<\/code> header as the bare key. Do not add <code>Bearer <\/code> in front: the OTP API refuses it.<\/p>\n<pre><code class=\"language-python\">\"authorization\": self.api_key,  # bare key, no \"Bearer \", never in the URL<\/code><\/pre>\n<p>The kit never retries a send or resend on its own, because a retry after a timeout could send, and charge, twice. It retries once, after 1 second, only when the connection could not be opened or Fast2SMS answered 502, 503 or 504 with an error page.<\/p>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Get your OTP ID in a few minutes<\/strong><p>Create a Smart OTP template on SMS or WhatsApp and plug it into the Django starter kit.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Security notes<\/h2>\n<h3>Never expose the API key<\/h3>\n<ul>\n<li>Call Fast2SMS only from your server. Never put the API key in JavaScript, a mobile app or a page the browser can download.<\/li>\n<li>Keep the key in <code>.env<\/code> or environment variables, out of git. If it ever leaks, click <strong>Reset<\/strong> on the <strong>API Key<\/strong> page; the old key stops working.<\/li>\n<li>Turn on <strong>API Security<\/strong> and whitelist your server&#8217;s public IP, so a stolen key does not work from anywhere else.<\/li>\n<li>The kit never writes the OTP or the full key to its logs. Mobiles are logged as <code>98xxxxxx10<\/code>.<\/li>\n<\/ul>\n<h3>Rate limits<\/h3>\n<p>Every send costs money, so limit who can press <strong>Send OTP<\/strong>. There are three layers:<\/p>\n<ul>\n<li><strong>The kit&#8217;s wait:<\/strong> the Resend button works only after <code>OTP_RESEND_WAIT_SECONDS<\/code> (30 by default). Clicks before that make no API call.<\/li>\n<li><strong>Fast2SMS limits:<\/strong> the <strong>SMS Resend \/ Time Limit<\/strong> in <strong>OTP Settings<\/strong> (10 seconds if not set, 0 to 3600) and the fixed cap of 5 sends per number in 10 minutes.<\/li>\n<li><strong>Your own limit:<\/strong> add a limit per IP address or a CAPTCHA on the Send button. Bots that try many different numbers are not stopped by per-number limits.<\/li>\n<\/ul>\n<p>The send, verify and resend views accept POST only and use Django&#8217;s CSRF check. Before going live, set <code>DEBUG = False<\/code> and your own <code>SECRET_KEY<\/code>.<\/p>\n<h3>Verify attempts<\/h3>\n<p>Set <strong>Max Verify OTP Limit (Per SMS)<\/strong> in <strong>Smart OTP<\/strong> &gt; <strong>OTP Settings<\/strong>. It can be 1 to 100 and is 10 if you never set it; 3 to 5 suits most login pages. When the limit is reached, the code stops working and the kit shows &#8220;Too many wrong tries&#8221; with a <strong>Send new code<\/strong> button.<\/p>\n<figure class=\"f2s-shot\"><img src=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-settings-hd-13-scaled.webp\" width=\"1440\" height=\"900\" loading=\"lazy\" decoding=\"async\" alt=\"OTP Settings page with Max Verify OTP Limit set to 5 and SMS Resend Time Limit set to 30 seconds\"><figcaption>Five tries per code and a 30-second wait between sends.<\/figcaption><\/figure>\n<div class=\"f2s-note f2s-note--warn\">After &#8220;Too many wrong tries&#8221; or &#8220;This code has expired&#8221;, give the user a fresh code with <code>client.send(mobile, otp_id)<\/code>. Do not re-send the old code. In the kit, the <strong>Send new code<\/strong> button calls <code>client.resend_or_send(mobile, otp_id)<\/code>; for a stricter setup, change it to call send when the last verify ended in <code>max_attempts<\/code>.<\/div>\n<p>Every send and every resend is charged at your OTP rate; verify is free. A fallback message on the second channel is also charged. See the current rates on the <a href=\"https:\/\/www.fast2sms.com\/otp-sms\">OTP SMS page<\/a>.<\/p>\n<div class=\"f2s-note f2s-volume\"><p><strong>Sending in bulk?<\/strong> For high OTP volumes our team offers discounted rates. <a href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Talk to our team<\/a> or see <a href=\"https:\/\/www.fast2sms.com\/bulk-sms-pricing\">OTP pricing<\/a>.<\/p><\/div>\n<p>Use HTTPS on the live site. After a correct code the kit starts a new session (or sign-in cookie), which stops session fixation, and every form carries a CSRF token.<\/p>\n<h2>OTP over DLT SMS: the second Django kit<\/h2>\n<p>Smart OTP is the easier choice. If you would rather send OTPs through your own approved DLT OTP template with the DLT SMS API, use our &#8220;OTP over DLT&#8221; kit for the same stack. It has the same login page, but the work is split differently:<\/p>\n<ul>\n<li><strong>Your app makes the code<\/strong> with a secure random generator and keeps only an HMAC-SHA256 hash of it, with the expiry time and a try counter. The code is never stored, logged or shown.<\/li>\n<li><strong>Fast2SMS only delivers the SMS.<\/strong> In <code>dlt<\/code> mode the kit calls <code>\/dev\/bulkV2<\/code> with <code>route=dlt<\/code>, your sender ID and the template&#8217;s Message ID. In <code>dlt_manual<\/code> mode it calls <code>\/dev\/custom<\/code> with <code>route=dlt_manual<\/code>, your Entity ID, the 19-digit DLT Template ID and the full text.<\/li>\n<li><strong>Verify happens in your app<\/strong> with a constant-time compare. No API call, no charge.<\/li>\n<li><strong>Resend sends a new code<\/strong> and the old one stops working.<\/li>\n<\/ul>\n<p>The two calls are <code>otp_service().send_otp(mobile)<\/code> and <code>otp_service().verify_otp(mobile, code)<\/code>. These are the DLT settings in its <code>.env<\/code>, next to the API key and an <code>OTP_HASH_SECRET<\/code> (a long random string; the app will not start without it):<\/p>\n<pre><code class=\"language-bash\"># How to send: dlt (DLT SMS, default) or dlt_manual (DLT Manual).\nOTP_SEND_MODE=dlt\n\n# Your approved DLT sender ID, exactly as in DLT Manager (case matters).\nFAST2SMS_SENDER_ID=FSTSMS\n\n# DLT SMS: the \"Message ID\" from the template card in DLT Manager. NOT the 19-digit DLT Template ID.\nFAST2SMS_DLT_MESSAGE_ID=111111\nFAST2SMS_DLT_VARIABLES={otp}\n\n# DLT Manual: the full approved DLT text, with {otp} where the code goes.\nFAST2SMS_DLT_MANUAL_TEXT=Your OTP is {otp} for Login. -Demo\nFAST2SMS_DLT_ENTITY_ID=1101234567890123456\nFAST2SMS_DLT_TEMPLATE_ID=1107123456789012345<\/code><\/pre>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>Rule<\/th>\n<th>Default<\/th>\n<th>Setting<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Code length<\/td>\n<td>6 digits (4 to 6 allowed)<\/td>\n<td><code>OTP_LENGTH<\/code><\/td>\n<\/tr>\n<tr>\n<td>Code expires after<\/td>\n<td>5 minutes<\/td>\n<td><code>OTP_EXPIRY_MINUTES<\/code><\/td>\n<\/tr>\n<tr>\n<td>Wrong tries per code<\/td>\n<td>5, then the code is deleted<\/td>\n<td><code>OTP_MAX_ATTEMPTS<\/code><\/td>\n<\/tr>\n<tr>\n<td>Wait between sends to one number<\/td>\n<td>30 seconds<\/td>\n<td><code>OTP_RESEND_WAIT_SECONDS<\/code><\/td>\n<\/tr>\n<tr>\n<td>Sends per number per hour<\/td>\n<td>5<\/td>\n<td><code>OTP_MAX_SENDS_PER_HOUR<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"f2s-note f2s-note--warn\">Use the <strong>Message ID<\/strong> from the template card in <strong>DLT Manager<\/strong>, not the 19-digit DLT Template ID. The sender ID is case-sensitive. In <a href=\"\/help\/dlt-manual-api-guide\/\">DLT Manual<\/a> mode, Fast2SMS does not check your text against the template: if it does not match exactly, the SMS fails at the operator and is not refunded.<\/div>\n<p>OTP records live in Django&#8217;s cache through a small <code>CacheStore<\/code> in <code>views.py<\/code>. The default <code>LocMemCache<\/code> works for one process only; set a shared cache such as Redis if you run several. This kit was run with Django 6.1.3 against the mock server in both modes: 20 of 20 tests and the 11-step browser test passed each time.<\/p>\n<p class=\"f2s-kit-wrap\"><a class=\"f2s-kit\" href=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/fast2sms-otp-dlt-python-django.zip\" download><svg class=\"f2s-kit__icon\" width=\"28\" height=\"28\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path fill=\"#7F56D9\" d=\"M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z\"\/><path fill=\"#FFFFFF\" d=\"M14 2v6h6\"\/><path fill=\"#FFFFFF\" d=\"M9 6h2v2H9zm2 2h2v2h-2zM9 10h2v2H9zm2 2h2v2h-2zm-2 2h4v4H9z\"\/><rect x=\"10\" y=\"15.4\" width=\"2\" height=\"1.6\" fill=\"#7F56D9\"\/><\/svg><span class=\"f2s-kit__text\"><strong>Download the OTP over DLT starter kit (zip)<\/strong><span class=\"f2s-kit__meta\">fast2sms-otp-dlt-python-django.zip &middot; 26 KB<\/span><\/span><span class=\"f2s-kit__btn\">Download .zip<\/span><\/a><\/p>\n<h2>Common problems and fixes<\/h2>\n<div class=\"f2s-facts\">\n<table>\n<thead>\n<tr>\n<th>What you see<\/th>\n<th>Why<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&#8220;SMS login is not set up correctly&#8221; and <code>Invalid authorization key<\/code> in the log<\/td>\n<td>Wrong key, or <code>Bearer <\/code> in front of it<\/td>\n<td>Copy the key again from <strong>API Key<\/strong> and send it bare.<\/td>\n<\/tr>\n<tr>\n<td><code>Authorization Key Disabled<\/code> (413) in the log<\/td>\n<td>API Access is off<\/td>\n<td>Switch on <strong>API Access<\/strong> on the API Key page.<\/td>\n<\/tr>\n<tr>\n<td><code>IP is blacklisted<\/code> (414) in the log<\/td>\n<td><a href=\"\/help\/api-security-ip-whitelist\/\">API Security<\/a> is on and your server IP is not listed<\/td>\n<td>Add the server&#8217;s public IP in <strong>API Security<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Could not send the code: Invalid OTP ID&#8221;<\/td>\n<td>The OTP ID is wrong, deleted or from another account<\/td>\n<td>Copy it from <strong>OTP Template List<\/strong>, in the same account as the key.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Please wait N seconds before asking for a new code.&#8221;<\/td>\n<td>Fast2SMS cooldown for this number<\/td>\n<td>Wait, or change the time in <strong>OTP Settings<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Could not send the code: Insufficient wallet balance&#8221;<\/td>\n<td>Low balance<\/td>\n<td>Recharge with <strong>Add Amount<\/strong>.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Maximum resend limit (5 times) reached&#8221;<\/td>\n<td>5 sends to this number in 10 minutes<\/td>\n<td>Wait and try later.<\/td>\n<\/tr>\n<tr>\n<td>&#8220;Could not reach the SMS service.&#8221;<\/td>\n<td>Network problem, or Fast2SMS was busy<\/td>\n<td>Try again in a minute.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Test without sending SMS<\/h2>\n<p>Each kit has a fake Fast2SMS server in its <code>mock<\/code> folder (it needs Python 3). It never sends an SMS, and with it the correct code is always <code>123456<\/code>. Start it, then run the tests in a second terminal:<\/p>\n<pre><code class=\"language-bash\">python mock\/mock_fast2sms.py\nFAST2SMS_BASE_URL=http:\/\/127.0.0.1:4010 python -m unittest discover -s tests -v<\/code><\/pre>\n<p>To click through the login page with the mock, set <code>FAST2SMS_API_KEY=TEST_KEY_OK<\/code> and <code>FAST2SMS_BASE_URL=http:\/\/127.0.0.1:4010<\/code> in <code>.env<\/code>. Remove <code>FAST2SMS_BASE_URL<\/code> before you go live.<\/p>\n<section class=\"f2s-faq\">\n<h2>Frequently asked questions<\/h2>\n<h3>Does the kit log the user in with django.contrib.auth?<\/h3>\n<p>Not by itself. After a correct code it stores the verified mobile in the session. In your project, find or create the <code>User<\/code> for that mobile at that point and call <code>django.contrib.auth.login()<\/code>.<\/p>\n<h3>Can I use it with Django REST Framework?<\/h3>\n<p>Yes. The client in <code>fast2sms_smart_otp.py<\/code> is plain Python. Call <code>send<\/code>, <code>verify<\/code> and <code>resend_or_send<\/code> from your API views and keep the same rate limits.<\/p>\n<h3>Is the starter kit free?<\/h3>\n<p>Yes. The kit is free under the MIT license. You pay only for the OTPs you send from your Fast2SMS wallet.<\/p>\n<h3>Can the same code send the OTP on WhatsApp?<\/h3>\n<p>Yes. The code only knows the OTP ID. If that OTP ID uses a WhatsApp authentication template, or has a WhatsApp fallback, Fast2SMS handles the channel and your code stays the same.<\/p>\n<h3>The page says the code was sent, but no SMS arrived. Why?<\/h3>\n<p>&#8220;OTP sent successfully&#8221; means Fast2SMS accepted the request. Check the status in <strong>Smart OTP<\/strong> &gt; <strong>Delivery Report<\/strong>. If the message failed and you set a fallback, the same OTP goes out once on the other channel.<\/p>\n<h3>How many times can a user resend the OTP?<\/h3>\n<p>Up to 4 times: Fast2SMS allows 5 sends of one OTP ID to a number in 10 minutes, counting the first. The wait between sends comes from your OTP Settings and the kit&#8217;s 30-second Resend wait.<\/p>\n<\/section>\n<aside class=\"f2s-cta\" aria-label=\"Get started with Fast2SMS\"><div class=\"f2s-cta__copy\"><strong class=\"f2s-cta__title\">Start sending OTPs from Django<\/strong><p>Sign up, create your OTP template and log users in with SMS or WhatsApp codes.<\/p><\/div><div class=\"f2s-cta__actions\"><a class=\"f2s-cta__btn f2s-cta__btn--primary\" href=\"https:\/\/www.fast2sms.com\/\"><span>Sign up free<\/span> <span class=\"f2sh-btn__arrow\" aria-hidden=\"true\">&rarr;<\/span><\/a><a class=\"f2s-cta__btn f2s-cta__btn--ghost\" href=\"https:\/\/www.fast2sms.com\/meet\/\" target=\"_blank\" rel=\"noopener\">Book a free meeting<\/a><\/div><\/aside>\n<h2>Related guides<\/h2>\n<ul>\n<li><a href=\"\/help\/smart-otp-setup-guide-fast2sms\/\">Smart OTP in Fast2SMS: set up OTP on SMS and WhatsApp with fallback<\/a><\/li>\n<li><a href=\"\/help\/dlt-manager-entity-sender-template-guide\/\">DLT Manager in Fast2SMS: add Entity ID, Sender ID and templates<\/a><\/li>\n<li><a href=\"\/help\/fast2sms-webhooks-setup-delivery-reports\/\">Webhooks in Fast2SMS: get delivery reports on your own URL<\/a><\/li>\n<li><a href=\"https:\/\/www.fast2sms.com\/help\/how-to-get-dlt-template-id-for-otp-and-transactional-sms\/\">How to get a DLT Template ID for OTP and transactional SMS<\/a><\/li>\n<li><a href=\"https:\/\/www.fast2sms.com\/otp-sms\">Fast2SMS OTP SMS<\/a><\/li>\n<li><a href=\"https:\/\/docs.fast2sms.com\">Fast2SMS API documentation<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows you how to add a Django OTP login page to your project with Fast2SMS Smart OTP. Our starter kit is a drop-in Django app called fast2sms_otp. You add it to INSTALLED_APPS, mount its URLs and set two values, and users can log in with a code sent to their mobile by SMS [&hellip;]<\/p>\n","protected":false},"featured_media":18713,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[],"class_list":["post-18727","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-otp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Django OTP Login with Smart OTP Starter Kit | Fast2SMS<\/title>\n<meta name=\"description\" content=\"Add Django OTP login to your project with Fast2SMS Smart OTP. Drop in the free starter app, add your API key and OTP ID, then send and verify codes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Django OTP Login with Smart OTP Starter Kit | Fast2SMS\" \/>\n<meta property=\"og:description\" content=\"Add Django OTP login to your project with Fast2SMS Smart OTP. Drop in the free starter app, add your API key and OTP ID, then send and verify codes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/\" \/>\n<meta property=\"og:site_name\" content=\"Fast2SMS\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Fast2SMS\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T18:41:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-18T19:21:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-4-scaled.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fast2sms\" \/>\n<meta name=\"twitter:site\" content=\"@fast2sms\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/\"},\"author\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"headline\":\"Django OTP login with Fast2SMS Smart OTP (starter kit)\",\"datePublished\":\"2026-11-18T18:41:19+00:00\",\"dateModified\":\"2026-11-18T19:21:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/\"},\"wordCount\":2222,\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-add-sms-filled-hd-4-scaled.webp\",\"articleSection\":[\"API\",\"OTP\"],\"inLanguage\":\"en-IN\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/\",\"name\":\"Django OTP Login with Smart OTP Starter Kit | Fast2SMS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-add-sms-filled-hd-4-scaled.webp\",\"datePublished\":\"2026-11-18T18:41:19+00:00\",\"dateModified\":\"2026-11-18T19:21:02+00:00\",\"description\":\"Add Django OTP login to your project with Fast2SMS Smart OTP. Drop in the free starter app, add your API key and OTP ID, then send and verify codes.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/#breadcrumb\"},\"inLanguage\":\"en-IN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-IN\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-add-sms-filled-hd-4-scaled.webp\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/smart-otp-add-sms-filled-hd-4-scaled.webp\",\"width\":2560,\"height\":1600,\"caption\":\"Add OTP Template window on the SMS Channel tab with entity, sender and DLT template selected and the variable buttons below the preview\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/otp-login-django-fast2sms\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"API\",\"item\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/api\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Django OTP login with Fast2SMS Smart OTP (starter kit)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/#website\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/help\\\/\",\"name\":\"Fast2SMS\",\"description\":\"Help\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\"},\"inLanguage\":\"en-IN\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#organization\",\"name\":\"Fast2SMS\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\",\"url\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"contentUrl\":\"https:\\\/\\\/www.fast2sms.com\\\/Fast2SMS.png\",\"caption\":\"Fast2SMS\"},\"image\":{\"@id\":\"https:\\\/\\\/www.fast2sms.com\\\/#logo\"},\"email\":\"support@fast2sms.com\",\"telephone\":\"+91-6262778822\",\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Fast2SMS\",\"https:\\\/\\\/www.instagram.com\\\/fast2sms\",\"https:\\\/\\\/x.com\\\/fast2sms\",\"https:\\\/\\\/www.youtube.com\\\/Fast2SMSofficial\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/fast2sms\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Django OTP Login with Smart OTP Starter Kit | Fast2SMS","description":"Add Django OTP login to your project with Fast2SMS Smart OTP. Drop in the free starter app, add your API key and OTP ID, then send and verify codes.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/","og_locale":"en_US","og_type":"article","og_title":"Django OTP Login with Smart OTP Starter Kit | Fast2SMS","og_description":"Add Django OTP login to your project with Fast2SMS Smart OTP. Drop in the free starter app, add your API key and OTP ID, then send and verify codes.","og_url":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/","og_site_name":"Fast2SMS","article_publisher":"https:\/\/www.facebook.com\/Fast2SMS\/","article_published_time":"2026-11-18T18:41:19+00:00","article_modified_time":"2026-11-18T19:21:02+00:00","og_image":[{"width":2560,"height":1600,"url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-4-scaled.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_creator":"@fast2sms","twitter_site":"@fast2sms","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/#article","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/"},"author":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"headline":"Django OTP login with Fast2SMS Smart OTP (starter kit)","datePublished":"2026-11-18T18:41:19+00:00","dateModified":"2026-11-18T19:21:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/"},"wordCount":2222,"publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-4-scaled.webp","articleSection":["API","OTP"],"inLanguage":"en-IN"},{"@type":"WebPage","@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/","url":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/","name":"Django OTP Login with Smart OTP Starter Kit | Fast2SMS","isPartOf":{"@id":"https:\/\/www.fast2sms.com\/help\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/#primaryimage"},"image":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/#primaryimage"},"thumbnailUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-4-scaled.webp","datePublished":"2026-11-18T18:41:19+00:00","dateModified":"2026-11-18T19:21:02+00:00","description":"Add Django OTP login to your project with Fast2SMS Smart OTP. Drop in the free starter app, add your API key and OTP ID, then send and verify codes.","breadcrumb":{"@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/#breadcrumb"},"inLanguage":"en-IN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/"]}]},{"@type":"ImageObject","inLanguage":"en-IN","@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/#primaryimage","url":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-4-scaled.webp","contentUrl":"https:\/\/www.fast2sms.com\/help\/wp-content\/uploads\/2026\/11\/smart-otp-add-sms-filled-hd-4-scaled.webp","width":2560,"height":1600,"caption":"Add OTP Template window on the SMS Channel tab with entity, sender and DLT template selected and the variable buttons below the preview"},{"@type":"BreadcrumbList","@id":"https:\/\/www.fast2sms.com\/help\/otp-login-django-fast2sms\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fast2sms.com\/help\/"},{"@type":"ListItem","position":2,"name":"API","item":"https:\/\/www.fast2sms.com\/help\/api\/"},{"@type":"ListItem","position":3,"name":"Django OTP login with Fast2SMS Smart OTP (starter kit)"}]},{"@type":"WebSite","@id":"https:\/\/www.fast2sms.com\/help\/#website","url":"https:\/\/www.fast2sms.com\/help\/","name":"Fast2SMS","description":"Help","publisher":{"@id":"https:\/\/www.fast2sms.com\/#organization"},"inLanguage":"en-IN"},{"@type":"Organization","@id":"https:\/\/www.fast2sms.com\/#organization","name":"Fast2SMS","url":"https:\/\/www.fast2sms.com\/","logo":{"@type":"ImageObject","@id":"https:\/\/www.fast2sms.com\/#logo","url":"https:\/\/www.fast2sms.com\/Fast2SMS.png","contentUrl":"https:\/\/www.fast2sms.com\/Fast2SMS.png","caption":"Fast2SMS"},"image":{"@id":"https:\/\/www.fast2sms.com\/#logo"},"email":"support@fast2sms.com","telephone":"+91-6262778822","sameAs":["https:\/\/www.facebook.com\/Fast2SMS","https:\/\/www.instagram.com\/fast2sms","https:\/\/x.com\/fast2sms","https:\/\/www.youtube.com\/Fast2SMSofficial","https:\/\/www.linkedin.com\/company\/fast2sms"]}]}},"_links":{"self":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/comments?post=18727"}],"version-history":[{"count":1,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18727\/revisions"}],"predecessor-version":[{"id":19367,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/posts\/18727\/revisions\/19367"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media\/18713"}],"wp:attachment":[{"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/media?parent=18727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/categories?post=18727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fast2sms.com\/help\/wp-json\/wp\/v2\/tags?post=18727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}