├── .github
├── FUNDING.yml
└── workflows
│ └── django.yml
├── Dockerfile
├── LICENSE.md
├── README.md
└── urlshortener
├── Procfile
├── db.sqlite3
├── manage.py
├── requirements.txt
├── runtime.txt
├── shortener
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-39.pyc
│ ├── admin.cpython-39.pyc
│ ├── apps.cpython-39.pyc
│ ├── models.cpython-39.pyc
│ ├── urls.cpython-39.pyc
│ └── views.cpython-39.pyc
├── admin.py
├── apps.py
├── migrations
│ ├── 0001_initial.py
│ ├── __init__.py
│ └── __pycache__
│ │ ├── 0001_initial.cpython-39.pyc
│ │ └── __init__.cpython-39.pyc
├── models.py
├── tests.py
├── urls.py
└── views.py
├── templates
└── index.html
└── urlshortener
├── __init__.py
├── __pycache__
├── __init__.cpython-39.pyc
├── settings.cpython-39.pyc
├── urls.cpython-39.pyc
└── wsgi.cpython-39.pyc
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [Pal-Sandeep,] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13 | custom: ['https://paytm.me/YyD-Wkw']
14 |
--------------------------------------------------------------------------------
/.github/workflows/django.yml:
--------------------------------------------------------------------------------
1 | name: Django CI
2 |
3 | on:
4 | push:
5 | branches: [ "main" ]
6 | pull_request:
7 | branches: [ "main" ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 | strategy:
14 | max-parallel: 4
15 | matrix:
16 | python-version: [3.7, 3.8, 3.9]
17 |
18 | steps:
19 | - uses: actions/checkout@v3
20 | - name: Set up Python ${{ matrix.python-version }}
21 | uses: actions/setup-python@v3
22 | with:
23 | python-version: ${{ matrix.python-version }}
24 | - name: Install Dependencies
25 | run: |
26 | python -m pip install --upgrade pip
27 | pip install django
28 |
29 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # base image
2 | FROM python:3.8
3 | ENV PYTHONUNBUFFERED 1
4 |
5 | WORKDIR /app
6 |
7 | ADD . /app
8 |
9 | COPY . /app
10 |
11 | COPY ./urlshortener/requirements.txt /app/requirements.txt
12 |
13 | RUN pip install -r requirements.txt
14 |
15 | RUN python ./urlshortener/manage.py makemigrations
16 |
17 | RUN python ./urlshortener/manage.py migrate
18 |
19 | EXPOSE 8000
20 |
21 | CMD python ./urlshortener/manage.py runserver 0.0.0.0:8000
22 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Sandeep Pal
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Django URL Shortener
2 | A URL Shortener App using Django
3 |
Simply Click in about section on link are you direct to open URL Shortener page.
4 |
--------------------------------------------------------------------------------
/urlshortener/Procfile:
--------------------------------------------------------------------------------
1 | web: gunicorn urlshortener.wsgi:application --log-file -
--------------------------------------------------------------------------------
/urlshortener/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/db.sqlite3
--------------------------------------------------------------------------------
/urlshortener/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | """Run administrative tasks."""
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'urlshortener.settings')
10 | try:
11 | from django.core.management import execute_from_command_line
12 | except ImportError as exc:
13 | raise ImportError(
14 | "Couldn't import Django. Are you sure it's installed and "
15 | "available on your PYTHONPATH environment variable? Did you "
16 | "forget to activate a virtual environment?"
17 | ) from exc
18 | execute_from_command_line(sys.argv)
19 |
20 |
21 | if __name__ == '__main__':
22 | main()
23 |
--------------------------------------------------------------------------------
/urlshortener/requirements.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/requirements.txt
--------------------------------------------------------------------------------
/urlshortener/runtime.txt:
--------------------------------------------------------------------------------
1 | python-3.9.12
--------------------------------------------------------------------------------
/urlshortener/shortener/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/__init__.py
--------------------------------------------------------------------------------
/urlshortener/shortener/__pycache__/__init__.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/__pycache__/__init__.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/shortener/__pycache__/admin.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/__pycache__/admin.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/shortener/__pycache__/apps.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/__pycache__/apps.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/shortener/__pycache__/models.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/__pycache__/models.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/shortener/__pycache__/urls.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/__pycache__/urls.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/shortener/__pycache__/views.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/__pycache__/views.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/shortener/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 | from .models import Url
3 |
4 | # Register your models here.
5 |
6 | admin.site.register(Url)
--------------------------------------------------------------------------------
/urlshortener/shortener/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class ShortenerConfig(AppConfig):
5 | default_auto_field = 'django.db.models.BigAutoField'
6 | name = 'shortener'
7 |
--------------------------------------------------------------------------------
/urlshortener/shortener/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.2.5 on 2022-06-03 13:13
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | initial = True
9 |
10 | dependencies = [
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Url',
16 | fields=[
17 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18 | ('link', models.CharField(max_length=10000)),
19 | ('uuid', models.CharField(max_length=10)),
20 | ],
21 | ),
22 | ]
23 |
--------------------------------------------------------------------------------
/urlshortener/shortener/migrations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/migrations/__init__.py
--------------------------------------------------------------------------------
/urlshortener/shortener/migrations/__pycache__/0001_initial.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/migrations/__pycache__/0001_initial.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/shortener/migrations/__pycache__/__init__.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/shortener/migrations/__pycache__/__init__.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/shortener/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | # Create your models here.
4 | class Url(models.Model):
5 | link = models.CharField(max_length=10000)
6 | uuid = models.CharField(max_length=10)
--------------------------------------------------------------------------------
/urlshortener/shortener/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/urlshortener/shortener/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 | from . import views
3 |
4 | urlpatterns = [
5 | path('',views.index,name='index'),
6 | path('create',views.create,name='create'),
7 | path('',views.go, name = 'go'),
8 | ]
--------------------------------------------------------------------------------
/urlshortener/shortener/views.py:
--------------------------------------------------------------------------------
1 | from django.http import HttpResponse
2 | from django.shortcuts import redirect, render
3 | import uuid
4 | from .models import Url
5 | # Create your views here.
6 | def index(request):
7 | return render(request,'index.html')
8 |
9 | def create(request):
10 | if request.method == 'POST':
11 | link = request.POST['link']
12 | uid = str(uuid.uuid4())[:5]
13 | new_url = Url(link=link,uuid= uid)
14 | new_url.save()
15 | return HttpResponse(uid)
16 |
17 | def go(request,pk):
18 | url_details = Url.objects.get(uuid=pk)
19 | return redirect('https://'+url_details.link)
20 |
21 |
--------------------------------------------------------------------------------
/urlshortener/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
75 |
76 |
77 | URL Shortener
78 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/urlshortener/urlshortener/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/urlshortener/__init__.py
--------------------------------------------------------------------------------
/urlshortener/urlshortener/__pycache__/__init__.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/urlshortener/__pycache__/__init__.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/urlshortener/__pycache__/settings.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/urlshortener/__pycache__/settings.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/urlshortener/__pycache__/urls.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/urlshortener/__pycache__/urls.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/urlshortener/__pycache__/wsgi.cpython-39.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/backendbuilderdev/Django-URL-Shortener/b00541ca2dafb400f3d96252cf70726b9e78d3da/urlshortener/urlshortener/__pycache__/wsgi.cpython-39.pyc
--------------------------------------------------------------------------------
/urlshortener/urlshortener/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for urlshortener project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'urlshortener.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/urlshortener/urlshortener/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for urlshortener project.
3 |
4 | Generated by 'django-admin startproject' using Django 3.2.5.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/3.2/ref/settings/
11 | """
12 |
13 | from pathlib import Path
14 | import os
15 | import django_heroku
16 | import dj_database_url
17 | # Build paths inside the project like this: BASE_DIR / 'subdir'.
18 | BASE_DIR = Path(__file__).resolve().parent.parent
19 |
20 |
21 | # Quick-start development settings - unsuitable for production
22 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
23 |
24 | # SECURITY WARNING: keep the secret key used in production secret!
25 | SECRET_KEY = 'django-insecure-^cyd444ti9sfg4r11hmum3*&9$9hy#_muaqal$n+b!@^)#cgq$'
26 |
27 | # SECURITY WARNING: don't run with debug turned on in production!
28 | DEBUG = True
29 |
30 | ALLOWED_HOSTS = ['*']
31 |
32 |
33 | # Application definition
34 |
35 | INSTALLED_APPS = [
36 | 'django.contrib.admin',
37 | 'django.contrib.auth',
38 | 'django.contrib.contenttypes',
39 | 'django.contrib.sessions',
40 | 'django.contrib.messages',
41 | 'django.contrib.staticfiles',
42 | 'shortener',
43 | ]
44 |
45 | MIDDLEWARE = [
46 | 'django.middleware.security.SecurityMiddleware',
47 | 'django.contrib.sessions.middleware.SessionMiddleware',
48 | 'django.middleware.common.CommonMiddleware',
49 | 'django.middleware.csrf.CsrfViewMiddleware',
50 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
51 | 'django.contrib.messages.middleware.MessageMiddleware',
52 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
53 | ]
54 |
55 | ROOT_URLCONF = 'urlshortener.urls'
56 |
57 | TEMPLATES = [
58 | {
59 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
60 | 'DIRS': [BASE_DIR/'templates'],
61 | 'APP_DIRS': True,
62 | 'OPTIONS': {
63 | 'context_processors': [
64 | 'django.template.context_processors.debug',
65 | 'django.template.context_processors.request',
66 | 'django.contrib.auth.context_processors.auth',
67 | 'django.contrib.messages.context_processors.messages',
68 | ],
69 | },
70 | },
71 | ]
72 |
73 | WSGI_APPLICATION = 'urlshortener.wsgi.application'
74 |
75 |
76 | # Database
77 | # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
78 |
79 | DATABASES = {
80 | 'default': {
81 | 'ENGINE': 'django.db.backends.sqlite3',
82 | 'NAME': BASE_DIR / 'db.sqlite3',
83 | }
84 | }
85 |
86 |
87 | # Password validation
88 | # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
89 |
90 | AUTH_PASSWORD_VALIDATORS = [
91 | {
92 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
93 | },
94 | {
95 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
96 | },
97 | {
98 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
99 | },
100 | {
101 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
102 | },
103 | ]
104 |
105 |
106 | # Internationalization
107 | # https://docs.djangoproject.com/en/3.2/topics/i18n/
108 |
109 | LANGUAGE_CODE = 'en-us'
110 |
111 | TIME_ZONE = 'UTC'
112 |
113 | USE_I18N = True
114 |
115 | USE_L10N = True
116 |
117 | USE_TZ = True
118 |
119 |
120 | # Static files (CSS, JavaScript, Images)
121 | # https://docs.djangoproject.com/en/3.2/howto/static-files/
122 |
123 | STATIC_URL = '/static/'
124 | django_heroku.settings(locals())
125 |
126 | # Default primary key field type
127 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
128 |
129 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
130 |
--------------------------------------------------------------------------------
/urlshortener/urlshortener/urls.py:
--------------------------------------------------------------------------------
1 | """urlshortener URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/3.2/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.urls import include, path
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 | """
16 | from django.contrib import admin
17 | from django.urls import path,include
18 |
19 | urlpatterns = [
20 | path('admin/', admin.site.urls),
21 | path('',include('shortener.urls')),
22 | ]
--------------------------------------------------------------------------------
/urlshortener/urlshortener/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for urlshortener project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'urlshortener.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------