{"id":16175308,"url":"https://github.com/app-generator/django-learn-by-coding","last_synced_at":"2026-03-01T03:01:58.952Z","repository":{"id":100502840,"uuid":"378567195","full_name":"app-generator/django-learn-by-coding","owner":"app-generator","description":"Django Web Framework - Learn by Coding | AppSeed","archived":false,"fork":false,"pushed_at":"2022-03-29T08:34:01.000Z","size":19,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-07T18:50:01.266Z","etag":null,"topics":["appseed-sample","django","learn-by-coding"],"latest_commit_sha":null,"homepage":"https://appseed.us","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/app-generator.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-20T05:35:59.000Z","updated_at":"2023-09-29T21:24:55.000Z","dependencies_parsed_at":"2023-05-15T11:15:07.374Z","dependency_job_id":null,"html_url":"https://github.com/app-generator/django-learn-by-coding","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/app-generator/django-learn-by-coding","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/app-generator%2Fdjango-learn-by-coding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/app-generator%2Fdjango-learn-by-coding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/app-generator%2Fdjango-learn-by-coding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/app-generator%2Fdjango-learn-by-coding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/app-generator","download_url":"https://codeload.github.com/app-generator/django-learn-by-coding/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/app-generator%2Fdjango-learn-by-coding/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29959284,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T01:47:18.291Z","status":"online","status_checked_at":"2026-03-01T02:00:07.437Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appseed-sample","django","learn-by-coding"],"created_at":"2024-10-10T04:44:35.695Z","updated_at":"2026-03-01T03:01:58.921Z","avatar_url":"https://github.com/app-generator.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Learn Django by Coding\n\nOpen-source project provided by AppSeed to help beginners accommodate and learn Django faster. For newcomers, Django is a popular web framework designed and actively supported by Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel.  \n\n\u003e **For support and more [Django Samples](https://appseed.us/admin-dashboards/django) join [AppSeed](https://appseed.us).**\n\n\u003cbr /\u003e\n\n## Create Django project\n\n\u003e Create a virtual environment\n\n```bash \n$ # Linux-based systems\n    $ virtualenv env\n    $ source env/bin/activate  \n```\n\nFor Windows systems, the syntax is different\n\n```bash\n$ virtualenv env\n$ .\\env\\Scripts\\activate\n```\n\n\u003cbr /\u003e\n\n\u003e Install Django using PIP, the official package manager for Python\n\n```bash\n$ pip install django\n```\n\n\u003cbr /\u003e\n\n\u003e Create project directory\n\n```bash\n$ mkdir learn-django\n$ cd learn-django\n```\n\n\u003cbr /\u003e\n\n\u003e Create project core\n\n```bash\n$ django-admin startproject config .\n```\n\n\u003cbr /\u003e\n\n\u003e Set up the database\n\n```bash\n$ python manage.py makemigrations\n$ python manage.py migrate\n```\n\n\u003cbr /\u003e\n\n\u003e Start the project\n\n```bash\n$ python manage.py runserver \n$\n$ # Access the web app in browser: http://127.0.0.1:8000/\n```\n\n\u003cbr /\u003e\n\n## Generate PDF Files \n\n\u003e Install dependencies\n\n```bash\n$ pip install reportlab\n```\n\n\u003cbr /\u003e\n\n\u003e Generate PDF file using Django Shell\n\n```python\n$ python ./manage.py shell\n\u003e\u003e\u003e\n\u003e\u003e\u003e import reportlab\n\u003e\u003e\u003e from reportlab.pdfgen import canvas \n\u003e\u003e\u003e p = canvas.Canvas('1.pdf')\n\u003e\u003e\u003e p.drawString(200, 200, \"Hello world.\") \n\u003e\u003e\u003e p.showPage() \n\u003e\u003e\u003e p.save()\n```\n\nThe above code should create in the root of the project a new PDF file. To open the file, from the Django console, please type:\n\n```python\n\u003e\u003e\u003e import os,sys\n\u003e\u003e\u003e os.startfile('1.pdf', 'open')\n```\n\nThe `startfile` helper should open the `PDF` file using the default handler registered in the operating system.\n\n\u003cbr /\u003e\n\n\u003e PDF creation with dynamic content - `app_pdf/pdf_dw` \n\n```python\n# File Content: app_pdf/pdf_dw (partial content)\ndef pdf_dw(request):                                  \n\n    # Create the HttpResponse object with the appropriate PDF headers. \n    response = HttpResponse(content_type='application/pdf') \n\n    # Comment the line to see the PDF in the browser \n    response['Content-Disposition'] = 'attachment; filename=\"1.pdf\"' \n \n    # Create the PDF object, using the response object as its \"file.\" \n    p = canvas.Canvas(response)     \n\n    # READ Optional GET param\n    get_param = request.GET.get('name', 'World')\n    \n    # Generate unique timestamp\n    ts = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')\n\n    # Write content on the PDF \n    p.drawString(100, 500, \"Hello \" + get_param + \" (Dynamic PDF) - \" + ts ) \n \n    # Close the PDF object. \n    p.showPage() \n    p.save() \n\n    # Show the result to the user    \n    return response\n```\n\n\u003cbr /\u003e\n\n\u003e PDF creation with image - `app_pdf/pdf_img`\n\n```python\ndef pdf_img(request):                                  \n\n    # Create the HttpResponse object with the appropriate PDF headers. \n    response = HttpResponse(content_type='application/pdf') \n \n    # Create the PDF object, using the response object as its \"file.\" \n    p = canvas.Canvas(response)     \n\n    my_image = ImageReader('https://www.google.com/images/srpr/logo11w.png')\n    \n    p.drawImage(my_image, 10, 500, mask='auto')\n\n    # Close the PDF object. \n    p.showPage() \n    p.save() \n\n    # Show the result to the user    \n    return response\n```\n\n\u003cbr /\u003e\n\n## Create Custom Commands\n\n\u003e Create the new app\n\n```bash\npython manage.py startapp app_customcmd\n```\n\n**Inside the new app directory** create a structure as shown below:\n\n```bash\n\u003c PROJECT ROOT \u003e                          \u003c-- project directory\n |\n |-- app_customcmd/                                \u003c-- app directory\n |    |-- management/\n |    |\t   +-- __init__.py\n |    |    +-- commands/\n |    |         +-- __init__.py\n |    |         +-- cmd_....py  \u003c-- module where all commands are saved\n```\n\n\u003cbr /\u003e\n\n\u003e Update configuration to enable the new app\n\n```python\n# File content: config/settings.py (partial content)\n...\nINSTALLED_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n    'app_forms',\n    'app_pdf',\n    'app_customcmd',                     # \u003c-- NEW\n    'app',\n]\n...\n```\n\n\u003cbr /\u003e\n\n\u003e Code a new dummy command - new file `app_customcmd/management/commands/cmd_time.py`\n\n```python\n# File content: cmd_time.py\n\nfrom django.core.management.base import BaseCommand\nfrom django.utils import timezone\n\nclass Command(BaseCommand):\n    help = 'Displays current time'\n\n    def handle(self, *args, **kwargs):\n        time = timezone.now().strftime('%X')\n        self.stdout.write(\"It's %s\" % time)\n```\n\n\u003cbr /\u003e\n\n\u003e Registered Commands:\n\n- `cmd_time.py` - show current timestamp\n- `cmd_apps`    - list all registered apps\n- `cmd_models`  - list all apps and associated models\n- `cmd_showcfg` - list all CFG keys and values\n\n**Command Usage sample**\n\n```bash\n$ python manage.py cmd_models \n```\n\n**Sample output**\n\n```bash\nAPP -\u003e Administration\n         |- (model) -\u003e \u003cclass 'django.contrib.admin.models.LogEntry'\u003e\n APP -\u003e Authentication and Authorization\n         |- (model) -\u003e \u003cclass 'django.contrib.auth.models.Permission'\u003e\n         |- (model) -\u003e \u003cclass 'django.contrib.auth.models.Group'\u003e\n         |- (model) -\u003e \u003cclass 'django.contrib.auth.models.User'\u003e\n APP -\u003e Content Types\n         |- (model) -\u003e \u003cclass 'django.contrib.contenttypes.models.ContentType'\u003e\n APP -\u003e Sessions\n         |- (model) -\u003e \u003cclass 'django.contrib.sessions.models.Session'\u003e\n APP -\u003e Messages\n APP -\u003e Static Files\n APP -\u003e App_Forms\n APP -\u003e App_Pdf\n APP -\u003e App_Customcmd\n APP -\u003e App\n         |- (model) -\u003e \u003cclass 'app.models.Book'\u003e\n```\n\n\u003cbr /\u003e\n\n--- \nLearn Django by Coding - Provided and actively supported by AppSeed [App Generator](https://appseed.us)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapp-generator%2Fdjango-learn-by-coding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapp-generator%2Fdjango-learn-by-coding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapp-generator%2Fdjango-learn-by-coding/lists"}