{"id":75306,"date":"2020-01-18T14:17:16","date_gmt":"2020-01-18T08:47:16","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?p=75306"},"modified":"2024-04-12T14:17:13","modified_gmt":"2024-04-12T08:47:13","slug":"your-first-app","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/","title":{"rendered":"Your First App"},"content":{"rendered":"<p>Now that you\u2019ve verified the connection is working, it\u2019s time to create a <em>Django app<\/em> \u2014 a bundle of Django code, including models and views, that lives together in a single Python package and represents a full Django application.<\/p>\n<p>It\u2019s worth explaining the terminology here, because this tends to trip up beginners. We\u2019d already created a <em>project<\/em>, in Chapter 2, so what\u2019s the difference between a <em>project<\/em> and an <em>app<\/em>? The difference is that of configuration vs. code:<\/p>\n<ul>\n<li>A project is an instance of a certain set of Django apps, plus the configuration for those apps.Technically, the only requirement of a project is that it supplies a settings file, which defines the database connection information, the list of installed apps, the TEMPLATE_DIRS, and so forth.<\/li>\n<\/ul>\n<ul>\n<li>An app is a portable set of Django functionality, usually including models and views, that lives together in a single Python package.For example, Django comes with a number of apps, such as a commenting system and an automatic admin interface. A key thing to note about these apps is that they\u2019re portable and reusable across multiple projects.<\/li>\n<\/ul>\n<p>There are very few hard-and-fast rules about how you fit your Django code into this scheme; it\u2019s flexible. If you\u2019re building a simple Web site, you may use only a single app. If you\u2019re building a complex Web site with several unrelated pieces such as an e-commerce system and a message board, you\u2019ll probably want to split those into separate apps so that you\u2019ll be able to reuse them individually in the future.<\/p>\n<p>Indeed, you don\u2019t necessarily need to create apps at all, as evidenced by the example view functions we\u2019ve created so far in this book. In those cases, we simply created a file called views.py, filled it with view functions, and pointed our URLconf at those functions. No \u201capps\u201d were needed. However, there\u2019s one requirement regarding the app convention: if you\u2019re using Django\u2019s database layer (models), you must create a Django app. Models must live within apps. Thus, in order to start writing our models, we\u2019ll need to create a new app. Within the mysite project directory you created in Chapter 2, type this command to create a new app named books:<\/p>\n<pre>python manage.py startapp books<\/pre>\n<p>This command does not produce any output, but it does create a books directory within the mysite directory. Let\u2019s look at the contents of that directory (showing the project folder tree so you can see where the app should be located):<\/p>\n<pre>\\mysite_project\n   \\books\n     \\migrations\n     __init__.py\n     admin.py\n     apps.py\n     models.py\n     tests.py\n     views.py\n  \\mysite\n  \\templates\n  manage.py<\/pre>\n<p>These files will contain the models and views for this app. Have a look at models.py and views.py in your favorite text editor. Both files are empty, except for comments and an import in models.py. This is the blank slate for your Django app.<\/p>\n<p>&nbsp;<\/p>\n\n\n<p><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/certified-django-developer\/\" target=\"_blank\" rel=\"noreferrer noopener\">Back to Tutorial<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that you\u2019ve verified the connection is working, it\u2019s time to create a Django app \u2014 a bundle of Django code, including models and views, that lives together in a single Python package and represents a full Django application. It\u2019s worth explaining the terminology here, because this tends to trip up beginners. We\u2019d already created&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[8655],"tags":[8671],"class_list":["post-75306","page","type-page","status-publish","hentry","category-django-web-development","tag-your-first-app"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Your First App - Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Your First App - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Now that you\u2019ve verified the connection is working, it\u2019s time to create a Django app \u2014 a bundle of Django code, including models and views, that lives together in a single Python package and represents a full Django application. It\u2019s worth explaining the terminology here, because this tends to trip up beginners. We\u2019d already created...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:47:13+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/\",\"name\":\"Your First App - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2020-01-18T08:47:16+00:00\",\"dateModified\":\"2024-04-12T08:47:13+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Your First App\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Your First App - Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/","og_locale":"en_US","og_type":"article","og_title":"Your First App - Tutorial","og_description":"Now that you\u2019ve verified the connection is working, it\u2019s time to create a Django app \u2014 a bundle of Django code, including models and views, that lives together in a single Python package and represents a full Django application. It\u2019s worth explaining the terminology here, because this tends to trip up beginners. We\u2019d already created...","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:47:13+00:00","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/","name":"Your First App - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2020-01-18T08:47:16+00:00","dateModified":"2024-04-12T08:47:13+00:00","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/your-first-app\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Your First App"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=75306"}],"version-history":[{"count":4,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75306\/revisions"}],"predecessor-version":[{"id":83322,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75306\/revisions\/83322"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=75306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=75306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=75306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}