Breaking News

New Updates

Python Django - The Practical Guide

python -m pip install -U pip

python -m venv env_site

.\env_site\Scripts\activate

pip install django

django-admin startproject my_site

cd my_site

python manage.py runserver
Django Installation and Setup | Basic Project using MVT in Django



⚠ if you facing the issue: ⚠ ⚠

(env-site) G:\monthly_challeges>djanog-admin startproject monthly
'djanog-admin' is not recognized as an internal or external command,
operable program or batch file.
Check your PATH: Make sure Python is added to your system's PATH

It looks like you might be trying to use the `django-admin` command but it's not being recognized. This usually happens for a couple of reasons:
2. **Check your PATH**: Make sure Python is added to your system's PATH. You can do this by:
- On Windows: Go to System Properties > Environment Variables. Under "System variables", find the `Path` variable and add the path to your Python installation (e.g., `C:\Python310\` and `C:\Python310\Scripts\`).


Python automatic "rror" checking

To automatically show errors while typing in Visual Studio Code for Python Django, you can enable **real-time type checking** and **linting**. Here’s how you can set it up:

1. **Install the Python Extension**: Make sure you have the Python extension installed in VS Code. You can find it in the Extensions Marketplace.

2. **Install Pylance**: Pylance is a static type checker that provides rich IntelliSense and type checking. Install it from the Extensions Marketplace.

3. **Enable Type Checking**: Open your `settings.json` file (you can access it by pressing `Ctrl + Shift + P` and typing `Preferences: Open Settings (JSON)`). Add the following settings:
   ```json
   {
       "python.analysis.typeCheckingMode": "basic",
       "python.linting.enabled": true,
       "python.linting.mypyEnabled": true,
       "python.linting.mypyArgs": ["--ignore-missing-imports", "--follow-imports=silent", "--show-column-numbers", "--allow-untyped-defs", "--allow-subclassing-any", "--allow-untyped-calls", "--strict"]
   }
   ```
   This configuration enables basic type checking and linting with Mypy.

4. **Install Mypy**: If you haven’t already, install Mypy using pip:
   ```sh
   pip install mypy
   ```



With these settings, VS Code will automatically show errors and warnings as you type, helping you catch issues early on.

Does this help with what you were looking for?

projectname/urls.py

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('challenges/', include('challenges.urls')),
]


place hoder

app/urls.py

from django.shortcuts import render
from django.http import HttpResponse, HttpResponseNotFound

# # Create your views here.
# def sunday(request):
#     return HttpResponse("Hello, world. You're at the challenges index.")
# def monday(request):
#     return HttpResponse("working day started.")
# def tuesday(request):
#     return HttpResponse("working day started but not starte a futeresti.")
# def wednesday(request):
#     return HttpResponse("midday so shaves day.")


# def monthly_challenges(request, months):
#     challenges = None
#     if months == "january":
#         challenges = "Run a marathon"
#     elif months == "february":
#         challenges = "Walk a marathon"
#     else: 
#         return HttpResponseNotFound("Invalid month")
#     return HttpResponse(challenges)

# def monthly_challenges_number(request, months):
#     return HttpResponse(months)

new = {
    "chingam" : "malayal Month started",
    "thulaam" : "its partolly rainy day",
    "kanni" : 'very hot month',
}

def wordes_study(request, worde):
    # try:
        challenges = new[worde]
        return HttpResponse(challenges)
    # except:
        # return HttpResponseNotFound("This month is not support!")


app/views.py

from django.contrib import admin
from django.urls import path

from . import views
urlpatterns = [
    # traditional
    # path('sunday', views.sunday),
    # path('monday', views.monday),
    # path('tuesday', views.tuesday),
    # path('wednesday', views.wednesday),

    # int using placeholder
    # path('<int:months>', views.monthly_challenges_number),
    # int using placeholder
    # path('<str:months>', views.monthly_challenges),
    path('<str:worde>', views.wordes_study),

]

No comments