Connect DJANGO with mysql

32 views
Skip to first unread message

ruk91

unread,
Jan 11, 2019, 7:17:09 AM1/11/19
to Django users
I have developed a react front-end and it has been connected t the DJANGO REST Framework. Now I need to use MySQL for data retrieving. Can anyone guide me to that? Or just send me clear documentation or example.

Kasper Laudrup

unread,
Jan 11, 2019, 7:20:50 AM1/11/19
to django...@googlegroups.com
Hi ruk91,
How about this?:

https://www.digitalocean.com/community/tutorials/how-to-create-a-django-app-and-connect-it-to-a-database

You can probably skip most of it, but at least it seems to be pretty
detailed when it comes to using Django with MySQL.

Kind regards,

Kasper Laudrup

NAveeN Kumar Reddy

unread,
Jan 11, 2019, 7:29:53 AM1/11/19
to django...@googlegroups.com
"""
Django settings for djangoblog project.

Generated by 'django-admin startproject' using Django 2.0.6.

For more information on this file, see

For the full list of settings and their values, see
"""


from configurations import Configuration
import os



# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '$l6#02pj0xjru7u_bo=@lk9a@+73lpsj#z4i(q_o%hevf=9w97'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition
INSTALLED_APPS = [
                    'django.contrib.admin',
                    'django.contrib.auth',
                    'django.contrib.contenttypes',
                    'django.contrib.sessions',
                    'django.contrib.messages',
                    'django.contrib.staticfiles',
                    'users','dashboard','frontend',
                    'crispy_forms'
                ]


MIDDLEWARE = [
                'django.middleware.security.SecurityMiddleware',
                'django.contrib.sessions.middleware.SessionMiddleware',
                'django.middleware.common.CommonMiddleware',
                'django.middleware.csrf.CsrfViewMiddleware',
                'django.contrib.auth.middleware.AuthenticationMiddleware',
                'django.contrib.messages.middleware.MessageMiddleware',
                'django.middleware.clickjacking.XFrameOptionsMiddleware',
            ]

ROOT_URLCONF = 'djangoblog.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'djangoblog.wsgi.application'


# Database

DATABASES = {
                'default': {
                            'NAME'      : 'djangoblog',
                            'ENGINE'    : 'django.db.backends.mysql',
                            'USER'      : 'root',
                            'PASSWORD'  : '',
                            'HOST'      : 'localhost',
                            'OPTIONS'   : {
                                            'autocommit': True,
                                             },
                            }
}


# Password validation

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)

## ==========================================================================

# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")

MEDIA_URL  = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')

## ==========================================================================

#Email Settings
EMAIL_BACKEND       = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS       = True
EMAIL_HOST          = 'smtp.gmail.com'
EMAIL_HOST_USER     = '@gmail.com'
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT          = 587

## ==========================================================================

LOGIN_REDIRECT_URL  = '/home/index'
LOGOUT_REDIRECT_URL = '/accounts/login'


CRISPY_TEMPLATE_PACK = 'bootstrap4'


# Extra places for collectstatic to find static files.
# STATICFILES_DIRS = (
#     os.path.join(BASE_DIR, 'static'),
# )

# STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'


On Fri 11 Jan, 2019, 5:47 PM ruk91 <sajit...@gmail.com wrote:
I have developed a react front-end and it has been connected t the DJANGO REST Framework. Now I need to use MySQL for data retrieving. Can anyone guide me to that? Or just send me clear documentation or example.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/76e3dce8-b961-4eb0-a993-3d623149ee8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages