Download as pdf
Download as pdf
You are on page 1of 10
Experiment No : 01 Anstaitation of Python, Django and visual studio code editors can be ctemenstiated. Python clownloacl fe fostatiatea link https If wuw. pythoo. org | downloads / Nisual studio code cCownload & jostallation link + https: /l_ code. visualstudio. wr! Django installatos ¢ Open A command prompt fe type the following commond + Pip iastall_ django. x) Experinrent No: 02 Aira: Creation of virtual envircoment, Django pryut and App Should be demonsirated Follow these steps : Tastalt the pythea extens' - Open VS Code IDE and atek extensions. There automatically you will be shown pythoea extension ( make sure ypu Ore conneetedt to interne’) On your Ale system, uteate a profect foldes Th that felt, use the following command (ass appropriate de your compute) to create a virtual envircament Named env based on qour turent laterpreter + pythen =m venv env (44 windows) Open the projut ffcut in VS_ Code by tunning code. , or by Tunniag VS Cede and using the File > Open folded éommand. Tn VS Code, open the Command Patette Cviuwe » Comman -d Palette or Cetrl + shift +P) ). Then selek the pythoa: Select foterpreter Command + Dhe command presents a list of available—jateipreters that NS cocte can. locate automaticat ( your tise wit vary 5 é you cton't ace the desirecl interpreter, see configuring pythen environments in your Projat foldec thar starts sbeov or -\env q Create Q oun Teminal: To miu tuminal-> nus Te&minal option Creating — project Create a Ajange prope - . ‘Type the following command in the teeminal epened + Ajango-admin startproyect ps (aot forrowing Projed name is important sahich _refect to current rectory ) his startprojet tommand assumes that the cuneat fidu is your projet folder, and creates the folowing within it manage.py + She Django command-line administrative —vitility forthe __prdject You1un administrative commands for the projec ustag ——— python manage. py K wmmand L options] - 2 .A_sub folder named p__wshich_ontains the folloutag files : i fy Gott. py: an empty file that -tetis python that this folder iS_Q python patkage *) wsgiepy + an entry point for WSG1- compatible web Servert to Sewve your project... You typical leave this fleas = is aS 1b provicles. the hooks . for praduttios wie seivers - ) Sebtings. py + contains settings for Django project, which you modify inthe course of Aeuetopiag a_ — Web app, 19 vals. py: contains a table of contents Ar ane Django — ——__ - Project, which you also. -modify in_the_tourse = - of development. = Wik To veri hy Me Django. project, make sure_your Virtual ea environment is athvatid , thin. Start Dhanga's evelopmunt a ~ Server using the command —————pytnen manage. py sunsenver__ "Ine _ssver wuns.on_the clefault port 8000 7—and__you see Output like the flowing ele io the tuminol windero: ee Pf you want to_use a_i: _ 8000, Spedfy the port _mumber_an_ aay snmmand_tine, = ———-Suth__05___pythea _maanage-py__tunservei_ 5.000 Nery Serever Iby.-typiag : ee = = ——_pythen —maanage. py sunseever —— 7 ~ hen you_tun the Seaver the fist time, ik creates a_clefoule - = — SOLike database “inthe file db. sqrike3 , which ts intended! a —for_devetop mint purposes but can be used tn Productoo_ for ———————t9u0.<_velume web apps. Also, Django.buills in webserver ~~ 18__intendled onty—fr_lecal_otevdtopmint Purpose. When, deploy —to_utebhost, however, _Django_uses the host's —--heb___Sexver_instead. he _wosgi--py module ta the _ Django projet takes “ot. heat. Jloto_-the production | eee ee eee = | 7 My then you're done, chose the browser. window and stop the Stier 49 V5 Code using Chl4+C as indtcatect SIP windeous “Lee “a REES Rab in the — terminal de the VS Code luminal with your virtual Activated, run the administrative Utility's command in your Project — flaw environmunt startapp Puthen manage .py StartLapp lab4 Y Fhe eommand Heater a feller calied labt that wntding a numbu of code files and one subfeldu Of these, you Fequentey work witb views. py and modes. Py he migrations folde 15 used by Ojango's administ vrative UFity to manage database versions Shure are alao the files apps. py + admin. py , and tests. py 7 i eee eens CHK ERI, SF CRE UU MRR DEEDS WORD ee ra eemy Mp, e Experiment No: 03 3) Develop a _Djongo app that clisplays.cunsent late & time_in. Staver. — Tn _lak4 subfolder, make foliowiag changes to_Views. py + fiom —ajango. Shortcuts import wender OS yong PF _ feen ajango... http _ import Hit pResponse - — —Tmpork date time— het cunent- chaketime Ceequtst t — now + _olatetime. datetime. now 0 — biml_=_" St html sh now rekuro_HLtp Response (html) Tin __ project mamed p, make — auasiog a touurls. py —_-frem_ajango.. contrt imp ort_admia _ — from chjango . uals import path fom loot. views import cunent. caletime _usipattuns = [path Cedtl', cunt. cotefime), ] Output 194.0.0-1 : 8000/edt! It is now 202.4 - 05 -16 10: 3a. 02. 246694 Experiment No : 04 @_ Develop a Django app that Cisplays late tr ime 4 hours ahead and 4 hous before as an offset of cinunt clate And. time in Sexver. views. py troon _aljango . shortusts —tenport sender 7 - fren django. http innport__H EH pRes ponse —__Import__clatetime def _¢urrint. datetione (request) + _ Now = _dlatetime. clatetime. now) — html = "dit 4 bodys dhi2 t's now 5 XIhi > Noody - A thEmIS pow — return Http Response (hin!) _ def four. houn. ahead ( request) “dts ladetime. datetime. now) + ctatetime, timedeita ( hourt= 4) ——hieal = Khiml>< body hid Artec 4 hows tk willbe FS 4 /hiy —|j) 4 tbody > £1 trtenld” de ott _ = —,_retuin_-HitpResponse Chimi) bef four howe — before Crequent) + : - - dit = _dlatetie._clatetime nowl) + olatetime . timedetta ( hous =- 4) bodlyshir Belore 4 houre tk win_be 1s a Kho dy htm" Ede _rthirn __-Hitp Response Umbro!) fre ajango. conttb tmpart admin _ =e _ fran eljangs. urlt_lenpork._ path _____ from 1abd. viens _tenpork cnet. dateioe, four. houre ahead, our. hove. bebore - urlpatteng = . —— path Cs edt/', current. dateime) , - i path C fhica/’, four. hourt- ahead), _ a path (° thi! four. hours. before) , Olitput: 104.0.0.1 !8000/ edt] Tt's now ooag- 05-6 10:49: U6. 545039 194.0.0.1:8000] fhrsa/ After 4 hous it will be yoog- 05-16 141 39: 34. 844660 199.0.0.1: 8000 / fhreb] Before 4 hove it war w02g-05-16 46 : 42°00, 544367

You might also like