{"id":8680,"date":"2015-01-24T04:30:18","date_gmt":"2015-01-24T04:30:18","guid":{"rendered":"https:\/\/wp.okra.host\/article\/django-quickstart\/"},"modified":"2021-03-07T14:44:26","modified_gmt":"2021-03-07T13:44:26","slug":"django-quickstart","status":"publish","type":"ht_kb","link":"https:\/\/kb.okra.host\/de\/article\/django-quickstart\/","title":{"rendered":"Django-Schnellstart"},"content":{"rendered":"<h2 id=\"overview\" >\u00dcbersicht<\/h2>\n<p><a href=\"https:\/\/www.djangoproject.com\/\">Django<\/a> is a web framework based on <a href=\"https:\/\/www.python.org\/\">Python<\/a>. Python is available on all packages, and a Django application may be uploaded on any package. But, to create a new project on the server and complete this quickstart, a\u00a0package <a title=\"Ist ein Terminalzugang vorhanden?\" href=\"https:\/\/kb.okra.host\/de\/terminal\/is-terminal-access-available\/\">with terminal access<\/a> is\u00a0necessary. This quickstart covers using Django with <a href=\"https:\/\/www.phusionpassenger.com\/\">Passagier<\/a>\u00a0available on <a title=\"Ermitteln der Plattformversion\" href=\"https:\/\/kb.okra.host\/de\/platform\/determining-platform-version\/\">v6+ Plattformen<\/a>.<\/p>\n<h2 id=\"quickstart\" >Schnellstart<\/h2>\n<p>From the <a title=\"Zugriff auf das Terminal\" href=\"https:\/\/kb.okra.host\/de\/terminal\/accessing-terminal\/\">Terminal<\/a>, first install Django + MySQL from\u00a0PyPI using Python&#8217;s <a title=\"Installieren von Paketen\" href=\"https:\/\/kb.okra.host\/de\/python\/installing-packages\/\">package manager<\/a>, pip.<\/p>\n<p><code>pip-python install django mysql<\/code><\/p>\n<p style=\"padding-left: 30px\"><strong><span style=\"color: #0000ff\">Important (<em>v6+ Plattformen<\/em>)<\/span>:<\/strong>\u00a0On v6+ platforms, first designate a <a href=\"https:\/\/kb.okra.host\/de\/python\/changing-python-versions\/\">Python interpreter<\/a> (do not use the default, &#8220;system&#8221;), then after installation, change the <a title=\"Python-Bins k\u00f6nnen die Bibliothek nicht importieren\" href=\"https:\/\/kb.okra.host\/de\/python\/python-bins-fail-import-library\/\">interpreter location<\/a>\u00a0of <code>\/usr\/local\/bin\/django-admin<\/code>.<\/p>\n<p>Now, Django has been installed\u00a0on your account. Setup a Django application. We&#8217;ll modify Django slightly to create a web-accessible public\/ folder and keep code outside a URL-accessible resource, one level down from the <a title=\"Von wo aus werden die Inhalte der Website bereitgestellt?\" href=\"https:\/\/kb.okra.host\/de\/web-content\/where-is-site-content-served-from\/\">Dokumentenstamm<\/a>.<\/p>\n<ol>\n<li>Switch to \/var\/www to create a new project:\n<ul>\n<li><code>cd \/var\/www<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Initialize an application named myapp\n<ul>\n<li><code>django-admin startproject myapp<\/code><\/li>\n<li><span style=\"color: #0000ff\"><strong>Hinweis:<\/strong><\/span>\u00a0per documentation, it&#8217;s recommended not to initialize projects under \/var\/www. This is only true if \/var\/www is accessible as a <a title=\"Von wo aus werden die Inhalte der Website bereitgestellt?\" href=\"https:\/\/kb.okra.host\/de\/web-content\/where-is-site-content-served-from\/\">Dokumentenstamm<\/a> (which it is not)<\/li>\n<\/ul>\n<\/li>\n<li>Django creates a management controller\u00a0(<code>manage.py<\/code>) within the folder named after the project, in\u00a0addition to an app named after the project, one level down. Move to the app folder from <code>\/var\/www<\/code>:\n<ul>\n<li><code>cd myapp\/myapp<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Make a <code>\u00f6ffentlich\/<\/code> und <code>tmp\/<\/code> directory for serving public files and storing logs. tmp\/ will be used to control application restarts with Passenger.\n<ul>\n<li><code>mkdir tmp public<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Passenger will look for a file called <code>passagier_wsgi.py<\/code> inside <code>\/var\/www\/myapp\/myapp<\/code>, create a link to satisfy this\n<ul>\n<li><code>ln -s wsgi.py passenger_wsgi.py<\/code><\/li>\n<\/ul>\n<\/li>\n<li>Edit\u00a0<code>passagier_wsgi.py<\/code> to append your application path to Python. This requires 2 minor additions:\n<ul>\n<li><strong>Before:<\/strong>\n<pre data-language=\"python\"><code>import os\r\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"myapp.settings\")\r\nfrom django.core.wsgi import get_wsgi_application\r\napplication = get_wsgi_application()<\/code><\/pre>\n<\/li>\n<li><strong>After:<\/strong>\n<pre data-language=\"python\"><code>import os, sys\r\nsys.path.append(\"\/var\/www\/myapp\")\r\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"myapp.settings\")\r\nfrom django.core.wsgi import get_wsgi_application\r\napplication = get_wsgi_application()<\/code><\/pre>\n<\/li>\n<li><span style=\"color: #0000ff\"><strong>Explanation:<\/strong><\/span>\u00a0only the first 2 lines are changed: (1) <a href=\"https:\/\/docs.python.org\/2\/library\/sys.html\">sys module<\/a> is loaded after os, this is necessary for (2) appending a library path via <code>sys.path.append<\/code>, the value being the <em>project root<\/em> (<code>\/var\/www\/myapp<\/code> in this case).<\/li>\n<\/ul>\n<\/li>\n<li>Lastly, connect this application to a web-accessible path\n<ul>\n<li>visit <strong>Web<\/strong> &gt; <strong>Subdomains<\/strong> innerhalb der <a title=\"Anmeldung am Bedienfeld\" href=\"https:\/\/kb.okra.host\/de\/control-panel\/logging-into-the-control-panel\/\">Bedienfeld<\/a>. Create a new subdomain called <em>myapp\u00a0<\/em>with the <a title=\"Von wo aus werden die Inhalte der Website bereitgestellt?\" href=\"https:\/\/kb.okra.host\/de\/web-content\/where-is-site-content-served-from\/\">Dokumentenstamm<\/a> <code>\/var\/www\/myapp\/myapp\/public<\/code>\n<\/p>\n<div id=\"attachment_549\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/kb.okra.host\/wp-content\/uploads\/2015\/01\/django-subdomain-ex.png\" rel=\"lightbox-0\" data-lbwps-width=\"978\" data-lbwps-height=\"225\" data-lbwps-srcsmall=\"https:\/\/kb.okra.host\/wp-content\/uploads\/2015\/01\/django-subdomain-ex.png\"><img decoding=\"async\" aria-describedby=\"caption-attachment-549\" loading=\"lazy\" class=\"size-medium wp-image-549\" src=\"https:\/\/kb.okra.host\/wp-content\/uploads\/2015\/01\/django-subdomain-ex-300x69.png\" alt=\"Linking a Django subdomain underneath a project called myapp and its first app called &quot;myapp&quot; using Passenger.\" width=\"300\" height=\"69\" \/><\/a><\/p>\n<p id=\"caption-attachment-549\" class=\"wp-caption-text\">Linking a Django subdomain underneath a project called myapp and its first app called &#8220;myapp&#8221; using Passenger.<\/p>\n<\/div>\n<\/li>\n<\/ul>\n<\/li>\n<li><em><em><strong>Viel Spa\u00df!<\/strong><\/em><\/em>\n<\/p>\n<div id=\"attachment_557\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/kb.okra.host\/wp-content\/uploads\/2015\/01\/django-confirmation-page.png\" rel=\"lightbox-1\" data-lbwps-width=\"896\" data-lbwps-height=\"173\" data-lbwps-srcsmall=\"https:\/\/kb.okra.host\/wp-content\/uploads\/2015\/01\/django-confirmation-page.png\"><img decoding=\"async\" aria-describedby=\"caption-attachment-557\" loading=\"lazy\" class=\"size-medium wp-image-557\" src=\"https:\/\/kb.okra.host\/wp-content\/uploads\/2015\/01\/django-confirmation-page-300x58.png\" alt=\"Confirmation page that Django is up and running a-OK!\" width=\"300\" height=\"58\" \/><\/a><\/p>\n<p id=\"caption-attachment-557\" class=\"wp-caption-text\">Confirmation page that Django is up and running a-OK!<\/p>\n<\/div>\n<\/li>\n<\/ol>\n<h3 id=\"restarting-your-application\" >Restarting your application<\/h3>\n<p>An app may either be restarted upon each request or at a single point. To restart an app every invocation, create a file called always_restart.txt in tmp\/: <code>touch tmp\/always_restart.txt<\/code>. To perform a single restart, create a file called restart.txt in tmp\/: <code>touch tmp\/restart.txt<\/code>. Passenger, which handles\u00a0process management, will compare the timestamp with its internal record and restart as necessary. To restart a second time, either reissue the command or delete, then recreate the file to update its modification time.<\/p>\n<h3 id=\"viewing-launcher-errors\" >Anzeige von Fehlern im Startprogramm<\/h3>\n<p>On newer v6 platforms, launcher errors may be viewed through the consolidated log file, <code>\/var\/log\/passenger.log<\/code>.<\/p>\n<h2 id=\"see-also\" >Siehe auch<\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.djangoproject.com\/en\/1.7\/intro\/tutorial01\/\">Django tutorial<\/a><\/li>\n<li><a href=\"http:\/\/www.djangobook.com\/en\/2.0\/index.html\">The Django Book<\/a><\/li>\n<li><a href=\"https:\/\/www.airpair.com\/python\/posts\/django-flask-pyramid\">Django vs. Flask vs. Pyramide<\/a><\/li>\n<li>Django <a href=\"http:\/\/django.sandbox.apnscp.com\">demo<\/a> auf Sol, einer v6-Plattform<\/li>\n<\/ul>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Overview Django is a web framework based on Python. Python is available on all packages, and a Django application may be uploaded on any package. But, to create a new project on the server and complete this quickstart, a\u00a0package with terminal access is\u00a0necessary. This quickstart covers using Django with Passenger\u00a0available&#8230;<\/p>","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[65],"ht-kb-tag":[],"class_list":["post-8680","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-python"],"_links":{"self":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/comments?post=8680"}],"version-history":[{"count":1,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8680\/revisions"}],"predecessor-version":[{"id":8681,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8680\/revisions\/8681"}],"wp:attachment":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/media?parent=8680"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-category?post=8680"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-tag?post=8680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}