├── db.sqlite3 ├── manage.py ├── map ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── admin.cpython-39.pyc │ ├── apps.cpython-39.pyc │ ├── forms.cpython-39.pyc │ ├── models.cpython-39.pyc │ └── views.cpython-39.pyc ├── admin.py ├── apps.py ├── forms.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-39.pyc │ │ └── __init__.cpython-39.pyc ├── models.py ├── tests.py └── views.py ├── mapproject ├── __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 └── templates └── index.html /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/db.sqlite3 -------------------------------------------------------------------------------- /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', 'mapproject.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 | -------------------------------------------------------------------------------- /map/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/__init__.py -------------------------------------------------------------------------------- /map/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /map/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /map/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /map/__pycache__/forms.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/__pycache__/forms.cpython-39.pyc -------------------------------------------------------------------------------- /map/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /map/__pycache__/views.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/__pycache__/views.cpython-39.pyc -------------------------------------------------------------------------------- /map/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Search 3 | 4 | # Register your models here. 5 | admin.site.register(Search) 6 | -------------------------------------------------------------------------------- /map/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class MapConfig(AppConfig): 5 | name = 'map' 6 | -------------------------------------------------------------------------------- /map/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from .models import Search 3 | 4 | 5 | class SearchForm(forms.ModelForm): 6 | address = forms.CharField(label='') 7 | 8 | class Meta: 9 | model = Search 10 | fields = ['address', ] 11 | -------------------------------------------------------------------------------- /map/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.7 on 2021-04-04 00:57 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='Search', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('address', models.CharField(max_length=200, null=True)), 19 | ('date', models.DateTimeField(auto_now_add=True)), 20 | ], 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /map/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/migrations/__init__.py -------------------------------------------------------------------------------- /map/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /map/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/map/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /map/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | 5 | 6 | class Search(models.Model): 7 | address = models.CharField(max_length=200, null=True) 8 | date = models.DateTimeField(auto_now_add=True) 9 | 10 | def __str__(self): 11 | return self.address 12 | -------------------------------------------------------------------------------- /map/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /map/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect 2 | from django.http import HttpResponse 3 | from .models import Search 4 | from .forms import SearchForm 5 | import folium 6 | import geocoder 7 | 8 | # Create your views here. 9 | 10 | 11 | def index(request): 12 | if request.method == 'POST': 13 | form = SearchForm(request.POST) 14 | if form.is_valid(): 15 | form.save() 16 | return redirect('/') 17 | else: 18 | form = SearchForm() 19 | address = Search.objects.all().last() 20 | location = geocoder.osm(address) 21 | lat = location.lat 22 | lng = location.lng 23 | country = location.country 24 | if lat == None or lng == None: 25 | address.delete() 26 | return HttpResponse('You address input is invalid') 27 | 28 | # Create Map Object 29 | m = folium.Map(location=[19, -12], zoom_start=2) 30 | 31 | folium.Marker([lat, lng], tooltip='Click for more', 32 | popup=country).add_to(m) 33 | # Get HTML Representation of Map Object 34 | m = m._repr_html_() 35 | context = { 36 | 'm': m, 37 | 'form': form, 38 | } 39 | return render(request, 'index.html', context) 40 | -------------------------------------------------------------------------------- /mapproject/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/mapproject/__init__.py -------------------------------------------------------------------------------- /mapproject/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/mapproject/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /mapproject/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/mapproject/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /mapproject/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/mapproject/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /mapproject/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KenBroTech/Django-Map-Locator/663756462e35e1585e0e422e842cb037a909e90a/mapproject/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /mapproject/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for mapproject 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.1/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', 'mapproject.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /mapproject/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for mapproject project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1.7. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/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/3.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'q&6-776h2-=9y5a84+fq29l=a+p#_9ns77!qte^+fj550#x5(w' 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 | 'map.apps.MapConfig', 41 | 'crispy_forms', 42 | ] 43 | 44 | MIDDLEWARE = [ 45 | 'django.middleware.security.SecurityMiddleware', 46 | 'django.contrib.sessions.middleware.SessionMiddleware', 47 | 'django.middleware.common.CommonMiddleware', 48 | 'django.middleware.csrf.CsrfViewMiddleware', 49 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 50 | 'django.contrib.messages.middleware.MessageMiddleware', 51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 52 | ] 53 | 54 | ROOT_URLCONF = 'mapproject.urls' 55 | 56 | TEMPLATES = [ 57 | { 58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 | 'DIRS': [BASE_DIR/'templates'], 60 | 'APP_DIRS': True, 61 | 'OPTIONS': { 62 | 'context_processors': [ 63 | 'django.template.context_processors.debug', 64 | 'django.template.context_processors.request', 65 | 'django.contrib.auth.context_processors.auth', 66 | 'django.contrib.messages.context_processors.messages', 67 | ], 68 | }, 69 | }, 70 | ] 71 | 72 | WSGI_APPLICATION = 'mapproject.wsgi.application' 73 | 74 | 75 | # Database 76 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 77 | 78 | DATABASES = { 79 | 'default': { 80 | 'ENGINE': 'django.db.backends.sqlite3', 81 | 'NAME': BASE_DIR / 'db.sqlite3', 82 | } 83 | } 84 | 85 | 86 | # Password validation 87 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 88 | 89 | AUTH_PASSWORD_VALIDATORS = [ 90 | { 91 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 92 | }, 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 101 | }, 102 | ] 103 | 104 | 105 | CRISPY_TEMPLATE_PACK = 'bootstrap4' 106 | 107 | # Internationalization 108 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 109 | 110 | LANGUAGE_CODE = 'en-us' 111 | 112 | TIME_ZONE = 'UTC' 113 | 114 | USE_I18N = True 115 | 116 | USE_L10N = True 117 | 118 | USE_TZ = True 119 | 120 | 121 | # Static files (CSS, JavaScript, Images) 122 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 123 | 124 | STATIC_URL = '/static/' 125 | -------------------------------------------------------------------------------- /mapproject/urls.py: -------------------------------------------------------------------------------- 1 | """mapproject URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.1/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 18 | from map import views as map_views 19 | 20 | urlpatterns = [ 21 | path('admin/', admin.site.urls), 22 | path('', map_views.index, name='index'), 23 | ] 24 | -------------------------------------------------------------------------------- /mapproject/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mapproject 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.1/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', 'mapproject.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | {% load crispy_forms_tags %} 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | Home Page 15 | 16 | 17 | 18 | 19 | 42 | 43 |
44 |
45 |
46 | {{ m|safe }} 47 |
48 |
49 |
50 | 51 | 52 | 53 | 54 | 57 | 60 | 61 | 62 | 67 | 68 | 69 | --------------------------------------------------------------------------------