Monday, September 21, 2020

Personal experiments on Django



This is going to be a busy week with my RI talk tomorrow in the afternoon and subsequently my community event on Thursday. As a month without formal ERM classes, the month should be relaxed one, but everyday is kinda intense because I told myself to complete one week's worth of Coursera tutorials in one day. 

I'm in the middle of writing a full-scale web app using the Django framework and it's been really hard. For the basic functionality, I've been spending hours troubleshooting issues that, on hindsight, mostly involve not importing the right modules and not being thorough at replacing one string with another. 

I suspect we are about 1 month away from an actual product that I will launch for members of my community which is a simple qualitative-drive crowdsourced website for local stocks. I think it is possible to build a closed-community to update the latest news so that, on a glance, a user can assess the purely qualitative sentiment of a stock. Until then, I gotta get up to speed with multiple programming languages like Javascript and JQuery. 

The problem is that a developer needs more time to become good at framework. Once too much is adopted, there is a risk of the industry moving on. There are too much internal complexities hidden to a developer and this can slow the pace of adoption even if intense googling takes place.

To remedy this, even my CCAs are Django related. I was able to figure out how to run a simple Hello World program on Django without installing the complicated frameworks that make Django programming so difficult even for someone with strong Python fundamentals. 

The following program can be executed with one line of code "python hello.py runserver". A lot of code is crammed into one file but that's how I build up my Django fundamentals to take a shot at building my own start-up later this year:

import os

import sys


from django.conf import settings


DEBUG = os.environ.get('DEBUG','on') == 'on'

SECRET_KEY=os.environ.get('SECRET_KEY',{{ secret_key }})

ALLOWED_HOSTS=os.environ.get('ALLOWED_HOSTS','localhost').split(',')


settings.configure(

  DEBUG=DEBUG,

  SECRET_KEY=SECRET_KEY,

  ALLOWED_HOSTS=ALLOWED_HOSTS,

  ROOT_URLCONF=__name__,

  MIDDLEWARE_CLASSES=(

    'django.middleware.common.CommonMiddleware',

    'django.middleware.csrf.CsrfViewMiddleware',

    'django.middleware.clickjacking.XFrameOptionsMiddleware',

  ),

)


from django.conf.urls import url

from django.core.wsgi import get_wsgi_application

from django.http import HttpResponse


def index(request):

    return HttpResponse('Hello World')


urlpatterns=(

  url(r'^$', index),

)


applications = get_wsgi_application()


if __name__ == "__main__":

  from django.core.management import execute_from_command_line

  execute_from_command_line(sys.argv)  


 




No comments:

Post a Comment