from django.http import HttpResponse
def sample_function(request):
return HttpResponse(“Welcome to Django”)
python -m django –versionget_version() method as follows :import django
print(django.get_version())
python manage.py migrate (migrate command looks at the INSTALLED_APPS settings and creates database tables accordingly)python manage.py makemigrations (tells Django you have created/ changed your models)python manage.py sqlmigrate (sqlmigrate takes the migration names and returns their SQL)from django.urls import path
from . import views
urlpatterns = [
path('data/2020/', views.data_2020),
path('data/<int:year>/', views.data_year)
]
from django.shortcuts import render
from django.http import HttpResponse
def setcookie(request):
response = HttpResponse("Cookie Set")
response.set_cookie('python-tutorial', 'example.com')
return response
def getcookie(request):
tutorial = request.COOKIES['python-tutorial']
return HttpResponse("python tutorials @: "+ tutorial);
# importing HttResponse from library
from django.http import HttpResponse
def home(request):
# request is handled using HttpResponse object
return HttpResponse("Any kind of HTML Here")
get_prep_value() and vice versa using from_db_value() method. Therefore, fields are fundamental pieces in different Django APIs such as models and querysets. render(request, template_name, context=None, content_type=None, status=None, using=None)django.contrib.staticfiles is added to your INSTALLED_APPSSTATIC_URL = '/static/'STATICFILES_STORAGE.{% load static %}
<img src="{% static 'my_sample/xyz.jpg' %}" alt="XYZ image"/>
my_sample/static/my_sample/xyz.jpgclean_message().clean_fieldname(). Django form system automatically looks for this type of method. Thus, these are called custom validation rules in Django. (db_types()) which are used to map Python types to the database using get_prep_value() and the other way round using from_db_value() method. Therefore, fields are fundamental pieces in different Django APIs such as models and querysets.