Setting Up MKDocs for Your Django Project: A Quick Guide!

After scouring back and forth the world wide web looking for who’s content to devour it came to my notice that this content is the first of it’s kind so I would first like to give a special shoutout to my Mom, my Dad 😭😭😭.

So to kickoff, i would start…


This content originally appeared on DEV Community and was authored by Mr Chike

After scouring back and forth the world wide web looking for who's content to devour it came to my notice that this content is the first of it's kind so I would first like to give a special shoutout to my Mom, my Dad 😭😭😭.

So to kickoff, i would start by highlighting the steps to take to get it done. (You know like begin with the end in mind)

  • Create Django Project
  • Install MkDocs & Build Documentation Folder
  • Include Documentation Folder in STATICFILES_DIRS
  • Register Documentation Folder for Template Rendering
  • Setup Url Configuration for public visibility
  • Setup MKDocs Configuration
  • Insert Static Blocks in HTML File for Static File Management
  • Build your app...

  • Create Django Project

django-admin startproject google_docx
cd google_docx/
python3 -m venv env
source env/bin/activate
  • Install MkDocs & Build Documentation Folder
pip install mkdocs
mkdocs new docs
cd docs
mkdocs build

And now to take a breather before we continue, feel free to go gossip with caroline at the coffee corner, hopefully it doesn't come back to bite you.

Done with the talk? Let's continue then
Below is currently the file structure of the documentation.

docs/
β”œβ”€β”€ docs
β”‚   └── index.md
β”œβ”€β”€ mkdocs.yml
└── site
    β”œβ”€β”€ 404.html
    β”œβ”€β”€ css
    β”‚   β”œβ”€β”€ base.css
    β”‚   β”œβ”€β”€ bootstrap.min.css
    β”‚   β”œβ”€β”€ bootstrap.min.css.map
    β”‚   β”œβ”€β”€ brands.min.css
    β”‚   β”œβ”€β”€ fontawesome.min.css
    β”‚   β”œβ”€β”€ solid.min.css
    β”‚   └── v4-font-face.min.css
    β”œβ”€β”€ img
    β”‚   β”œβ”€β”€ favicon.ico
    β”‚   └── grid.png
    β”œβ”€β”€ index.html
    β”œβ”€β”€ js
    β”‚   β”œβ”€β”€ base.js
    β”‚   β”œβ”€β”€ bootstrap.bundle.min.js
    β”‚   β”œβ”€β”€ bootstrap.bundle.min.js.map
    β”‚   └── darkmode.js
    β”œβ”€β”€ search
    β”‚   β”œβ”€β”€ lunr.js
    β”‚   β”œβ”€β”€ main.js
    β”‚   β”œβ”€β”€ search_index.json
    β”‚   └── worker.js
    β”œβ”€β”€ sitemap.xml
    β”œβ”€β”€ sitemap.xml.gz
    └── webfonts
        β”œβ”€β”€ fa-brands-400.ttf
        β”œβ”€β”€ fa-brands-400.woff2
        β”œβ”€β”€ fa-regular-400.ttf
        β”œβ”€β”€ fa-regular-400.woff2
        β”œβ”€β”€ fa-solid-900.ttf
        β”œβ”€β”€ fa-solid-900.woff2
        β”œβ”€β”€ fa-v4compatibility.ttf
        └── fa-v4compatibility.woff2
google_docx/
β”œβ”€β”€ asgi.py
β”œβ”€β”€ __init__.py
β”œβ”€β”€ settings.py
β”œβ”€β”€ urls.py
└── wsgi.py

So to proceed, we would be heading to the next step.....

  • Include Documentation Folder in STATICFILES_DIRS & Register Documentation Folder for Template Rendering

Update the following in the settings.py file

STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, STATIC_URL)
STATICFILES_DIRS = [
    BASE_DIR / "docs/site",  # mkdocs static directory
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'docs/site')], # register directory for HTML template rendering
        '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',
            ],
        },
    },
]
  • Setup urls.py Configuration for public visibility
from django.contrib import admin
from django.urls import path
from django.views.generic import TemplateView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('docs/', TemplateView.as_view(template_name="index.html")),
]

  • Setup MKDocs Configuration

Update the mkdocs.yml file

site_name: Google Docx Documentation # Project Doc Name
site_dir: site 
site_url: http://127.0.0.1:8000/docs

run the mkdocs build command

mkdocs build
  • Insert Static Blocks in HTML File for Static File Management

NB:_ mkdocs by default generates index.html but django can only load static files like css and js with {% load static %} in html files. So keep in mind that when you update the document and build you would have to rerun this process._

<!DOCTYPE html>
<html lang="en" data-bs-theme="light">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="None">

        {% load static %}
        <link rel="canonical" href="http://127.0.0.1:8003/docs/">
        <link rel="shortcut icon" href="{% static 'img/favicon.ico' %}">
        <title>Google Docx Documentation</title>
        <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
        <link href="{% static 'css/fontawesome.min.css' %}" rel="stylesheet">
        <link href="{% static 'css/brands.min.css' %}" rel="stylesheet">
        <link href="{% static 'css/solid.min.css' %}" rel="stylesheet">
        <link href="{% static 'css/v4-font-face.min.css' %}" rel="stylesheet">
        <link href="{% static 'css/base.css' %}" rel="stylesheet">
        <link id="hljs-light" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github.min.css" >
        <link id="hljs-dark" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css" disabled>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
        <script>hljs.highlightAll();</script> 
    </head>

<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
<script>
     var base_url = ".",
     shortcuts = {"help": 191, "next": 78, "previous": 80, "search": 83};
</script>
<script src="{% static 'js/base.js' %}"></script>
<script src="{% static 'search/main.js' %}"></script>

The final outcome as you'll see below that it's up and running and the code can be found in django_mkdocs

Image description

Image description

Thanks for your attention so far and would love you to know i'm open to feedback and collaboration.


This content originally appeared on DEV Community and was authored by Mr Chike


Print Share Comment Cite Upload Translate Updates
APA

Mr Chike | Sciencx (2024-10-19T22:07:13+00:00) Setting Up MKDocs for Your Django Project: A Quick Guide!. Retrieved from https://www.scien.cx/2024/10/19/setting-up-mkdocs-for-your-django-project-a-quick-guide/

MLA
" » Setting Up MKDocs for Your Django Project: A Quick Guide!." Mr Chike | Sciencx - Saturday October 19, 2024, https://www.scien.cx/2024/10/19/setting-up-mkdocs-for-your-django-project-a-quick-guide/
HARVARD
Mr Chike | Sciencx Saturday October 19, 2024 » Setting Up MKDocs for Your Django Project: A Quick Guide!., viewed ,<https://www.scien.cx/2024/10/19/setting-up-mkdocs-for-your-django-project-a-quick-guide/>
VANCOUVER
Mr Chike | Sciencx - » Setting Up MKDocs for Your Django Project: A Quick Guide!. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/19/setting-up-mkdocs-for-your-django-project-a-quick-guide/
CHICAGO
" » Setting Up MKDocs for Your Django Project: A Quick Guide!." Mr Chike | Sciencx - Accessed . https://www.scien.cx/2024/10/19/setting-up-mkdocs-for-your-django-project-a-quick-guide/
IEEE
" » Setting Up MKDocs for Your Django Project: A Quick Guide!." Mr Chike | Sciencx [Online]. Available: https://www.scien.cx/2024/10/19/setting-up-mkdocs-for-your-django-project-a-quick-guide/. [Accessed: ]
rf:citation
» Setting Up MKDocs for Your Django Project: A Quick Guide! | Mr Chike | Sciencx | https://www.scien.cx/2024/10/19/setting-up-mkdocs-for-your-django-project-a-quick-guide/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.