Skip to content

Commit 7fb3d4b

Browse files
committed
push github
1 parent 07a3c9e commit 7fb3d4b

File tree

11 files changed

+414
-0
lines changed

11 files changed

+414
-0
lines changed

URL Shortener/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
# URL-Shortener
3+
4+
A simple and fast URL shortener! This allows to convert long URLs into shorter, more manageable links, making them easier to share, tweet, or send via email.
5+
6+
### Installation
7+
**1. Create a Folder where you want to save the project**
8+
9+
**2. Create a Virtual Environment and Activate**
10+
11+
Install Virtual Environment First
12+
```
13+
$ pip install virtualenv
14+
```
15+
16+
Create Virtual Environment
17+
18+
For Windows
19+
```
20+
$ python -m venv venv
21+
```
22+
For Mac
23+
```
24+
$ python3 -m venv venv
25+
```
26+
27+
Activate Virtual Environment
28+
29+
For Windows
30+
```
31+
$ source venv/scripts/activate
32+
```
33+
34+
For Mac
35+
```
36+
$ source venv/bin/activate
37+
```
38+
39+
**3. Clone this project**
40+
41+
```
42+
$ git clone https://github.com/saminmahmud/URL-Shortener.git
43+
```
44+
45+
Then, Enter the project
46+
```
47+
$ cd URL-Shortener
48+
```
49+
50+
**4. Install Requirements from 'requirements.txt'**
51+
```python
52+
$ pip install -r requirements.txt
53+
```
54+
55+
**5. Now Run Server**
56+
57+
Command for Windows:
58+
```python
59+
$ python manage.py runserver
60+
```
61+
62+
Command for Linux or Mac:
63+
```python
64+
$ python3 manage.py runserver
65+
```

URL Shortener/manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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', 'url_shortener.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()

URL Shortener/requirements.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
asgiref==3.8.1
2+
certifi==2024.8.30
3+
charset-normalizer==3.3.2
4+
Django==5.1.1
5+
idna==3.10
6+
pyperclip==1.9.0
7+
pyshorteners==1.0.1
8+
requests==2.32.3
9+
sqlparse==0.5.1
10+
tzdata==2024.2
11+
urllib3==2.2.3

URL Shortener/templates/home.html

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Url Shortener</title>
7+
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
8+
<link
9+
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
10+
rel="stylesheet"
11+
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
12+
crossorigin="anonymous"
13+
/>
14+
</head>
15+
<body style="background-color: #222; height: 100vh; display: flex; align-items: center; justify-content: center;">
16+
<section class=" bg-image " style="width:95%;">
17+
<div class="mask d-flex align-items-center h-100 gradient-custom-3">
18+
<div class="container h-100">
19+
<div
20+
class="row d-flex justify-content-center align-items-center h-100">
21+
<div class="col-12 col-md-9 col-lg-7 col-xl-6">
22+
<div class="card" style="border-radius: 15px; margin: auto;">
23+
<div class="card-body p-5">
24+
<h2 class="text-uppercase text-center mb-5">URL Shortener</h2>
25+
26+
<form id="myForm" method="POST">
27+
{% csrf_token %} {% for hidden_field in form.hidden_fields %}
28+
{{ hidden_field.errors }} {{ hidden_field }} {% endfor %}
29+
{% for field in form.visible_fields %}
30+
31+
<div class="form-outline mb-4">
32+
<input
33+
placeholder="Enter the url here"
34+
name="{{ field.name }}"
35+
id="{{ field.id_for_label }}"
36+
type="{{ field.widget_type }}"
37+
class="form-control form-control-lg"
38+
/>
39+
{% if field.errors %} {% for error in field.errors %}
40+
<p class="text-danger italic pb-2">{{ error }}</p>
41+
{% endfor %} {% endif %}
42+
</div>
43+
44+
{% endfor %}
45+
46+
<div class="d-flex justify-content-center">
47+
<button
48+
type="submit"
49+
class="btn btn-success btn-lg gradient-custom-4">
50+
Submit
51+
</button>
52+
</div>
53+
</form>
54+
</div>
55+
</div>
56+
</div>
57+
</div>
58+
</div>
59+
</div>
60+
</section>
61+
62+
<footer class="fixed-bottom border-top border-light">
63+
<div
64+
class="text-center p-3 text-white"
65+
style="background-color: #222422; font-size: small">
66+
©{% now "Y" %} All Rights Reserved By <strong>Samin Mahmud</strong>
67+
</div>
68+
</footer>
69+
70+
<script
71+
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
72+
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
73+
crossorigin="anonymous"
74+
></script>
75+
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.8/clipboard.min.js"></script>
76+
77+
<script>
78+
const linkFromBackend = "{{ link }}";
79+
// console.log(linkFromBackend);
80+
if (linkFromBackend && linkFromBackend !== "Give Valid Url") {
81+
Swal.fire({
82+
icon: "success",
83+
title: "Shortened URL:",
84+
html: `
85+
<a href='${linkFromBackend}' target='_blank'>${linkFromBackend}</a>
86+
<button id="copyButton" class="btn btn-primary">Copy</button>
87+
`,
88+
confirmButtonText: "Cancel",
89+
allowOutsideClick: false,
90+
allowEscapeKey: false,
91+
}).then((result) => {
92+
if (result.isConfirmed) {
93+
window.location.href = "/";
94+
}
95+
});
96+
97+
// Set up clipboard functionality
98+
const copyButton = document.getElementById("copyButton");
99+
const clipboard = new ClipboardJS(copyButton, {
100+
text: function () {
101+
return linkFromBackend;
102+
},
103+
});
104+
} else if (linkFromBackend && linkFromBackend === "Give Valid Url") {
105+
Swal.fire({
106+
icon: "warning",
107+
title: `
108+
<p>${linkFromBackend}</p>
109+
`,
110+
confirmButtonText: "Cancel",
111+
allowOutsideClick: false,
112+
allowEscapeKey: false,
113+
}).then((result) => {
114+
if (result.isConfirmed) {
115+
window.location.href = "/";
116+
}
117+
});
118+
}
119+
</script>
120+
</body>
121+
</html>

URL Shortener/url_shortener/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for url_shortener 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/4.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', 'url_shortener.settings')
15+
16+
application = get_asgi_application()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from django import forms
2+
3+
class UrlForm(forms.Form):
4+
link = forms.CharField(max_length=1000)
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""
2+
Django settings for url_shortener project.
3+
4+
Generated by 'django-admin startproject' using Django 4.2.7.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/4.2/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'django-insecure-h6i2mz0ityv87h4jezm)xbt_2!_-!j)nv(oh#%3kwsl9nf!tkt'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
]
41+
42+
MIDDLEWARE = [
43+
'django.middleware.security.SecurityMiddleware',
44+
'django.contrib.sessions.middleware.SessionMiddleware',
45+
'django.middleware.common.CommonMiddleware',
46+
'django.middleware.csrf.CsrfViewMiddleware',
47+
'django.contrib.auth.middleware.AuthenticationMiddleware',
48+
'django.contrib.messages.middleware.MessageMiddleware',
49+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
50+
]
51+
52+
ROOT_URLCONF = 'url_shortener.urls'
53+
54+
TEMPLATES = [
55+
{
56+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
57+
'DIRS': ['templates'],
58+
'APP_DIRS': True,
59+
'OPTIONS': {
60+
'context_processors': [
61+
'django.template.context_processors.debug',
62+
'django.template.context_processors.request',
63+
'django.contrib.auth.context_processors.auth',
64+
'django.contrib.messages.context_processors.messages',
65+
],
66+
},
67+
},
68+
]
69+
70+
WSGI_APPLICATION = 'url_shortener.wsgi.application'
71+
72+
73+
# Database
74+
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
75+
76+
DATABASES = {
77+
'default': {
78+
'ENGINE': 'django.db.backends.sqlite3',
79+
'NAME': BASE_DIR / 'db.sqlite3',
80+
}
81+
}
82+
83+
84+
# Password validation
85+
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
86+
87+
AUTH_PASSWORD_VALIDATORS = [
88+
{
89+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
90+
},
91+
{
92+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
93+
},
94+
{
95+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
96+
},
97+
{
98+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
99+
},
100+
]
101+
102+
103+
# Internationalization
104+
# https://docs.djangoproject.com/en/4.2/topics/i18n/
105+
106+
LANGUAGE_CODE = 'en-us'
107+
108+
TIME_ZONE = 'UTC'
109+
110+
USE_I18N = True
111+
112+
USE_TZ = True
113+
114+
115+
# Static files (CSS, JavaScript, Images)
116+
# https://docs.djangoproject.com/en/4.2/howto/static-files/
117+
118+
STATIC_URL = 'static/'
119+
120+
# Default primary key field type
121+
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
122+
123+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.contrib import admin
2+
from django.urls import path
3+
from .views import Urlgenerate
4+
5+
urlpatterns = [
6+
path('admin/', admin.site.urls),
7+
path('', Urlgenerate.as_view(), name="home")
8+
]

0 commit comments

Comments
 (0)