Installation
Install current Version (3.2.8)
❯ pip install django==3.2.8
❯ pip install django==3.2.8
❯ pip install django==3.2.8
Install next Version (4.0)
❯ pip install --pre django
❯ pip install --pre django
❯ pip install --pre django
Check installed version
❯ python -m django --version
❯ python -m django --version
❯ python -m django --version
❯ django-admin.exe version
❯ django-admin.exe version
❯ django-admin.exe version
First steps
The following steps are based on a summary of the Django Tutorial
Create project
django-admin startproject main
python manage.py runserver 8080
python manage.py startapp app_base
django-admin startproject main
cd working_with_django
python manage.py migrate
python manage.py runserver 8080
python manage.py startapp app_base
django-admin startproject main
cd working_with_django
python manage.py migrate
python manage.py runserver 8080
python manage.py startapp app_base
Create view
Create view in app_base/views.py
from django.http import HttpResponse
return HttpResponse("Hello, world. You're at the polls index.")
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
Add view to app_base/urls.py
from django.urls import path
path('', views.index, name='index'),
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
Add urls to project main/urls.py
from django.contrib import admin
from django.urls import include, path
path('admin/', admin.site.urls),
path('app_base/', include('app_base.urls')),
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('app_base/', include('app_base.urls')),
]
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('app_base/', include('app_base.urls')),
]
Create admin user
$ python manage.py createsuperuser
Username (leave blank to use 'user'): admin
Email address: admin@localhost
Superuser created successfully.
$ python manage.py createsuperuser
Username (leave blank to use 'user'): admin
Email address: admin@localhost
Password:
Password (again):
Superuser created successfully.
$ python manage.py createsuperuser
Username (leave blank to use 'user'): admin
Email address: admin@localhost
Password:
Password (again):
Superuser created successfully.
Create data and database
Create database model in app_base/models.py
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
Activating models in main/settings.py
'app_base.apps.AppBaseConfig',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
INSTALLED_APPS = [
'app_base.apps.AppBaseConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
INSTALLED_APPS = [
'app_base.apps.AppBaseConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
$ python manage.py makemigrations app_base
$ python manage.py sqlmigrate app_base 0001
$ python manage.py makemigrations app_base
$ python manage.py sqlmigrate app_base 0001
$ python manage.py makemigrations app_base
$ python manage.py sqlmigrate app_base 0001
Make app modifiable in the admin (app_base/admin.py)
from django.contrib import admin
from .models import Question
admin.site.register(Question)
from django.contrib import admin
from .models import Question
admin.site.register(Question)
from django.contrib import admin
from .models import Question
admin.site.register(Question)
Writing more views
Create views in app_base/views.py
def detail(request, question_id):
return HttpResponse("You're looking at question
def results(request, question_id):
response = "You're looking at the results of question
return HttpResponse(response
def vote(request, question_id):
return HttpResponse("You're voting on question
def detail(request, question_id):
return HttpResponse("You're looking at question
def results(request, question_id):
response = "You're looking at the results of question
return HttpResponse(response
def vote(request, question_id):
return HttpResponse("You're voting on question
def detail(request, question_id):
return HttpResponse("You're looking at question
def results(request, question_id):
response = "You're looking at the results of question
return HttpResponse(response
def vote(request, question_id):
return HttpResponse("You're voting on question
Add new views into app_base/urls.py
from django.urls import path
path('', views.index, name='index'),
path('<int:question_id>/', views.detail, name='detail'),
path('<int:question_id>/results/', views.results, name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('<int:question_id>/', views.detail, name='detail'),
path('<int:question_id>/results/', views.results, name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
]
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('<int:question_id>/', views.detail, name='detail'),
path('<int:question_id>/results/', views.results, name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
]
Add template in app_base/templates/polls/index.html
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
<p>No polls are available.</p>
<h4 class="wp-block-heading">Modify view in <strong>app_base/views.py</strong></h4>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.shortcuts import render
latest_question_list = Question.objects.order_by('-pub_date')[:5]
context = {'latest_question_list': latest_question_list}
return render(request, 'polls/index.html', context)</pre><h3 class="wp-block-heading">Raising a 404 error in app_base/views.py</h3><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from .models import Question
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/detail.html', {'question': question})</pre><h3 class="wp-block-heading">Create template <code>app_base/templates/polls/detail.html</code></h3><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""><h1>{{ question.question_text }}</h1>
<li>{{ choice.choice_text }}</li>
</ul></pre><h3 class="wp-block-heading">Removing hardcoded URLs in <code>app_base/templates/polls/index.html</code></h3><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="test" data-enlighter-group=""><li>
</li></pre><p>The way this works is by looking up the URL definition as specified in the app_base/urs.py</p><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">...
# the 'name' value as called by the {
path('<int:question_id>/', views.detail, name='detail'),
...</pre><h3 class="wp-block-heading">Namespacing URL names in <code>app_base/urls.py</code></h3><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">app_name = 'app_base'
...</pre><p>Then, modify link in <code>app_base/templates/polls/index.html</code></p><p>from <strong>url ‘detail’</strong> to <strong>url ‘app_base:detail’</strong></p><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="2" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""><li>
</li></pre><h3 class="wp-block-heading">Use generic views: Less code is better</h3><h4 class="wp-block-heading">Create class in <code>a</code>pp_views/views.py</h4><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class HomeView(generic.TemplateView):
template_name = 'index.html'</pre><h4 class="wp-block-heading">Create template <code>app_views/templates/index.html</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""><h1>App Views:</h1>
Welcome</pre><h4 class="wp-block-heading">Modify <code>app_views/urls.py</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="2" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
]</pre><h3 class="wp-block-heading">Add another app to main project</h3><h4 class="wp-block-heading">Create app</h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py startapp app_view
</pre><h4 class="wp-block-heading">Modify <code>main/urls.py</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">urlpatterns = [
path('admin/', admin.site.urls),
path('app_base/', include('app_base.urls')),
path('app_views/', include('app_views.urls')),
]</pre><h4 class="wp-block-heading">Add data model in <code>app_views/models.py</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.db import models
class DataItem(models.Model):
text = models.CharField(max_length=200)
data = models.IntegerField(default=0)
return self.text</pre><h4 class="wp-block-heading">Register data in <code>app_views/admin.py</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.contrib import admin
from .models import DataItem
admin.site.register(DataItem)</pre><h4 class="wp-block-heading">Activate models</h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations app_views
$ python manage.py sqlmigrate app_views 0001
$ python manage.py migrate app_views</pre><h2 class="wp-block-heading">Navigation / Redirection</h2><h3 class="wp-block-heading">Set root page of Django project</h3><p>When accessing your Django project, the root page will normaly doesn’n show your app homepage.</p><p>To change this, you hate to modiy the url handling.</p><p>In the following sample, replace <appname> with the name of your app</p><h4 class="wp-block-heading">Define a redirection view in your app (<strong>/<appname>/urls.py</strong>)</h4><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">def redirect_to_home(request):
return redirect('/<appname>')</pre><h4 class="wp-block-heading">Define path in the global urls.py (<strong>/main/urls.py</strong>)</h4><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="3,5,8" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.contrib import admin
from django.urls import include, path
from django.shortcuts import redirect
from <appname> import views
path('', views.redirect_to_home, name='home'),
path('<appname>/', include('<appname>.urls')),
path('admin/', admin.site.urls)
]</pre><p>Highlight current page in navigation menu</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""><div class="list-group">
</div></pre><h2 class="wp-block-heading">Using PostgresSQL Database</h2><h3 class="wp-block-heading">Install PostgresSQL</h3><h3 class="wp-block-heading">Create Superuser</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">createuser.exe --interactive --pwprompt</pre><h2 class="wp-block-heading">Logging</h2><h3 class="wp-block-heading"></h3><h2 class="wp-block-heading">Additional reading</h2><h3 class="wp-block-heading">Tutorials</h3><ul class="wp-block-list"><li><a href="https://realpython.com/django-redirects/">https://realpython.com/django-redirects/</a></li><li><a href="https://django-best-practices.readthedocs.io/en/latest/">https://django-best-practices.readthedocs.io/en/latest/</a></li><li><a href="https://www.geeksforgeeks.org/tag/python-django/">https://www.geeksforgeeks.org/tag/python-django/</a></li><li><a href="https://www.django-rest-framework.org">https://www.django-rest-framework.org</a></li></ul><h3 class="wp-block-heading">Testing</h3><ul class="wp-block-list"><li><a href="https://tox.readthedocs.io/en/latest/#">https://tox.readthedocs.io/en/latest/#</a></li></ul><h3 class="wp-block-heading">Blogs and Posts</h3><ul class="wp-block-list"><li><a href="https://medium.com/@humble_bee/django-basics-for-a-beginner-5d864e6aa084">Django Basics for a Beginner</a> at medium.com</li><li><a href="https://data-flair.training/blogs/django-quiz/">Django Quiz</a></li><li></li></ul><h2 class="wp-block-heading">Resolving problems</h2><h3 class="wp-block-heading">Wrong template is used</h3><p>The template system is using a search approach to find the specified template file, e.g. ‘home.html’.</p><p>If you created more than one apps with the same filenames for templates, the first one will be used.</p><p>Change the template folders and add the app name, e.g.</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">template/
home.html</pre><h2 class="wp-block-heading">Resolving error messages and erors</h2><h3 class="wp-block-heading">‘app_name’ is not a registered namespace</h3><p>One reason for this error is the usage of a namespace in a link.</p><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Back to <a href="{
<p>If you want to use this way of links, you have to define the namespace/appname in your <code><app>/urls.py</code> file</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">app_name = 'app_views'
path('', views.HomeView.as_view(), name='home'),
]</pre><h3 class="wp-block-heading">dependencies reference nonexistent parent node</h3><ul class="wp-block-list"><li>Recreate database and migration files</li><li>Remove all migration files under */migrations/00*.py</li><li>Remove all pycache folders under */__pycache__ and */*/__pycache__</li><li>Run migration again</li></ul><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations
$ python manage migrate</pre><h3 class="wp-block-heading"><a href="https://stackoverflow.com/questions/43871604/valueerror-dependency-on-app-with-no-migrations-customuser">V</a>alueError: Dependency on app with no migrations: customuser</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations</pre><h2 class="wp-block-heading">Project Structure</h2><h3 class="wp-block-heading">Running tasks with Makefile</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">PREFIX_PKG := app
clearcache: # Clear Cache
python3 manage.py clearcache
python3 manage.py runserver 8000
rm -rf dist $(PREFIX_PKG)*
cd polls && python3 setup.py sdist
mkdir polls.dist && mv polls/dist/* polls/$(PREFIX_PKG)* polls.dist
install_bootstrap: # Install Bootstrap Library
cd .. && yarn add bootstrap
rm -rf polls/static/bootstrap
mkdir polls/static/bootstrap
cp -R ../node_modules/bootstrap/dist/* polls/static/bootstrap
install_jquery: # Install jQuery Library
rm -rf polls/static/jquery
mkdir polls/static/jquery
cp ../node_modules/jquery/dist/* polls/static/jquery
install_bootstrap_from_source: # Install Bootstrap from Source
wget https://github.com/twbs/bootstrap/releases/download/v4.1.3/bootstrap-4.1.3-dist.zip -O install/bootstrap-4.1.3-dist.zip && \
unzip install/bootstrap-4.1.3-dist.zip -d polls/static/bootstrap/4.1.3</pre></pre>
{
<ul>
{
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{
</ul>
{
<p>No polls are available.</p>
{
<h4 class="wp-block-heading">Modify view in <strong>app_base/views.py</strong></h4>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.shortcuts import render
...
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
context = {'latest_question_list': latest_question_list}
return render(request, 'polls/index.html', context)</pre><h3 class="wp-block-heading">Raising a 404 error in app_base/views.py</h3><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from .models import Question
# ...
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/detail.html', {'question': question})</pre><h3 class="wp-block-heading">Create template <code>app_base/templates/polls/detail.html</code></h3><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""><h1>{{ question.question_text }}</h1>
<ul>
{
<li>{{ choice.choice_text }}</li>
{
</ul></pre><h3 class="wp-block-heading">Removing hardcoded URLs in <code>app_base/templates/polls/index.html</code></h3><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="test" data-enlighter-group=""><li>
<a href="{
</li></pre><p>The way this works is by looking up the URL definition as specified in the app_base/urs.py</p><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">...
# the 'name' value as called by the {
path('<int:question_id>/', views.detail, name='detail'),
...</pre><h3 class="wp-block-heading">Namespacing URL names in <code>app_base/urls.py</code></h3><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">app_name = 'app_base'
urlpatterns = [
...</pre><p>Then, modify link in <code>app_base/templates/polls/index.html</code></p><p>from <strong>url ‘detail’</strong> to <strong>url ‘app_base:detail’</strong></p><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="2" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""><li>
<a href="{
</li></pre><h3 class="wp-block-heading">Use generic views: Less code is better</h3><h4 class="wp-block-heading">Create class in <code>a</code>pp_views/views.py</h4><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">class HomeView(generic.TemplateView):
template_name = 'index.html'</pre><h4 class="wp-block-heading">Create template <code>app_views/templates/index.html</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""><h1>App Views:</h1>
Welcome</pre><h4 class="wp-block-heading">Modify <code>app_views/urls.py</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="2" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
]</pre><h3 class="wp-block-heading">Add another app to main project</h3><h4 class="wp-block-heading">Create app</h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py startapp app_view
</pre><h4 class="wp-block-heading">Modify <code>main/urls.py</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">urlpatterns = [
path('admin/', admin.site.urls),
path('app_base/', include('app_base.urls')),
path('app_views/', include('app_views.urls')),
]</pre><h4 class="wp-block-heading">Add data model in <code>app_views/models.py</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.db import models
class DataItem(models.Model):
text = models.CharField(max_length=200)
data = models.IntegerField(default=0)
def __str__(self):
return self.text</pre><h4 class="wp-block-heading">Register data in <code>app_views/admin.py</code></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.contrib import admin
from .models import DataItem
admin.site.register(DataItem)</pre><h4 class="wp-block-heading">Activate models</h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations app_views
$ python manage.py sqlmigrate app_views 0001
$ python manage.py migrate app_views</pre><h2 class="wp-block-heading">Navigation / Redirection</h2><h3 class="wp-block-heading">Set root page of Django project</h3><p>When accessing your Django project, the root page will normaly doesn’n show your app homepage.</p><p>To change this, you hate to modiy the url handling.</p><p>In the following sample, replace <appname> with the name of your app</p><h4 class="wp-block-heading">Define a redirection view in your app (<strong>/<appname>/urls.py</strong>)</h4><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">def redirect_to_home(request):
return redirect('/<appname>')</pre><h4 class="wp-block-heading">Define path in the global urls.py (<strong>/main/urls.py</strong>)</h4><pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="3,5,8" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">from django.contrib import admin
from django.urls import include, path
from django.shortcuts import redirect
from <appname> import views
urlpatterns = [
path('', views.redirect_to_home, name='home'),
path('<appname>/', include('<appname>.urls')),
path('admin/', admin.site.urls)
]</pre><p>Highlight current page in navigation menu</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""><div class="list-group">
<a href="{
Basic Upload
</a>
<a href="{
Progress Bar Upload
</a>
</div></pre><h2 class="wp-block-heading">Using PostgresSQL Database</h2><h3 class="wp-block-heading">Install PostgresSQL</h3><h3 class="wp-block-heading">Create Superuser</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">createuser.exe --interactive --pwprompt</pre><h2 class="wp-block-heading">Logging</h2><h3 class="wp-block-heading"></h3><h2 class="wp-block-heading">Additional reading</h2><h3 class="wp-block-heading">Tutorials</h3><ul class="wp-block-list"><li><a href="https://realpython.com/django-redirects/">https://realpython.com/django-redirects/</a></li><li><a href="https://django-best-practices.readthedocs.io/en/latest/">https://django-best-practices.readthedocs.io/en/latest/</a></li><li><a href="https://www.geeksforgeeks.org/tag/python-django/">https://www.geeksforgeeks.org/tag/python-django/</a></li><li><a href="https://www.django-rest-framework.org">https://www.django-rest-framework.org</a></li></ul><h3 class="wp-block-heading">Testing</h3><ul class="wp-block-list"><li><a href="https://tox.readthedocs.io/en/latest/#">https://tox.readthedocs.io/en/latest/#</a></li></ul><h3 class="wp-block-heading">Blogs and Posts</h3><ul class="wp-block-list"><li><a href="https://medium.com/@humble_bee/django-basics-for-a-beginner-5d864e6aa084">Django Basics for a Beginner</a> at medium.com</li><li><a href="https://data-flair.training/blogs/django-quiz/">Django Quiz</a></li><li></li></ul><h2 class="wp-block-heading">Resolving problems</h2><h3 class="wp-block-heading">Wrong template is used</h3><p>The template system is using a search approach to find the specified template file, e.g. ‘home.html’.</p><p>If you created more than one apps with the same filenames for templates, the first one will be used.</p><p>Change the template folders and add the app name, e.g.</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">template/
app_base/
home.html</pre><h2 class="wp-block-heading">Resolving error messages and erors</h2><h3 class="wp-block-heading">‘app_name’ is not a registered namespace</h3><p>One reason for this error is the usage of a namespace in a link.</p><pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Back to <a href="{
<p>If you want to use this way of links, you have to define the namespace/appname in your <code><app>/urls.py</code> file</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">app_name = 'app_views'
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
]</pre><h3 class="wp-block-heading">dependencies reference nonexistent parent node</h3><ul class="wp-block-list"><li>Recreate database and migration files</li><li>Remove all migration files under */migrations/00*.py</li><li>Remove all pycache folders under */__pycache__ and */*/__pycache__</li><li>Run migration again</li></ul><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations
$ python manage migrate</pre><h3 class="wp-block-heading"><a href="https://stackoverflow.com/questions/43871604/valueerror-dependency-on-app-with-no-migrations-customuser">V</a>alueError: Dependency on app with no migrations: customuser</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations</pre><h2 class="wp-block-heading">Project Structure</h2><h3 class="wp-block-heading">Running tasks with Makefile</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">PREFIX_PKG := app
default:
grep -E ':\s+#' Makefile
clearcache: # Clear Cache
python3 manage.py clearcache
run: # Run Server
python3 manage.py runserver 8000
deploy: # Deploy
rm -rf dist $(PREFIX_PKG)*
rm -rf polls.dist
cd polls && python3 setup.py sdist
mkdir polls.dist && mv polls/dist/* polls/$(PREFIX_PKG)* polls.dist
install_bootstrap: # Install Bootstrap Library
cd .. && yarn add bootstrap
rm -rf polls/static/bootstrap
mkdir polls/static/bootstrap
cp -R ../node_modules/bootstrap/dist/* polls/static/bootstrap
install_jquery: # Install jQuery Library
cd .. && yarn add jquery
rm -rf polls/static/jquery
mkdir polls/static/jquery
cp ../node_modules/jquery/dist/* polls/static/jquery
install_bootstrap_from_source: # Install Bootstrap from Source
mkdir -p install && \
wget https://github.com/twbs/bootstrap/releases/download/v4.1.3/bootstrap-4.1.3-dist.zip -O install/bootstrap-4.1.3-dist.zip && \
unzip install/bootstrap-4.1.3-dist.zip -d polls/static/bootstrap/4.1.3</pre></pre>
{
<ul>
{
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{
</ul>
{
<p>No polls are available.</p>
{
Modify view in app_base/views.py
from django.shortcuts import render
latest_question_list = Question.objects.order_by('-pub_date')[:5]
context = {'latest_question_list': latest_question_list}
return render(request, 'polls/index.html', context)
from django.shortcuts import render
...
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
context = {'latest_question_list': latest_question_list}
return render(request, 'polls/index.html', context)
from django.shortcuts import render
...
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
context = {'latest_question_list': latest_question_list}
return render(request, 'polls/index.html', context)
Raising a 404 error in app_base/views.py
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from .models import Question
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/detail.html', {'question': question})
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from .models import Question
# ...
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/detail.html', {'question': question})
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from .models import Question
# ...
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/detail.html', {'question': question})
Create template app_base/templates/polls/detail.html
<h1>{{ question.question_text }}</h1>
<li>{{ choice.choice_text }}</li>
<h1>{{ question.question_text }}</h1>
<ul>
{
<li>{{ choice.choice_text }}</li>
{
</ul>
<h1>{{ question.question_text }}</h1>
<ul>
{
<li>{{ choice.choice_text }}</li>
{
</ul>
Removing hardcoded URLs in app_base/templates/polls/index.html
<li>
<a href="{
</li>
The way this works is by looking up the URL definition as specified in the app_base/urs.py
# the 'name' value as called by the {
path('<int:question_id>/', views.detail, name='detail'),
...
# the 'name' value as called by the {
path('<int:question_id>/', views.detail, name='detail'),
...
...
# the 'name' value as called by the {
path('<int:question_id>/', views.detail, name='detail'),
...
Namespacing URL names in app_base/urls.py
app_name = 'app_base'
urlpatterns = [
...
app_name = 'app_base'
urlpatterns = [
...
Then, modify link in app_base/templates/polls/index.html
from url ‘detail’ to url ‘app_base:detail’
<li>
<a href="{
</li>
Use generic views: Less code is better
Create class in a
pp_views/views.py
class HomeView(generic.TemplateView):
template_name = 'index.html'
class HomeView(generic.TemplateView):
template_name = 'index.html'
class HomeView(generic.TemplateView):
template_name = 'index.html'
Create template app_views/templates/index.html
<h1>App Views:</h1>
Welcome
<h1>App Views:</h1>
Welcome
Modify app_views/urls.py
path('', views.HomeView.as_view(), name='home'),
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
]
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
]
Add another app to main project
Create app
$ python manage.py startapp app_view
$ python manage.py startapp app_view
$ python manage.py startapp app_view
Modify main/urls.py
path('admin/', admin.site.urls),
path('app_base/', include('app_base.urls')),
path('app_views/', include('app_views.urls')),
urlpatterns = [
path('admin/', admin.site.urls),
path('app_base/', include('app_base.urls')),
path('app_views/', include('app_views.urls')),
]
urlpatterns = [
path('admin/', admin.site.urls),
path('app_base/', include('app_base.urls')),
path('app_views/', include('app_views.urls')),
]
Add data model in app_views/models.py
from django.db import models
class DataItem(models.Model):
text = models.CharField(max_length=200)
data = models.IntegerField(default=0)
from django.db import models
class DataItem(models.Model):
text = models.CharField(max_length=200)
data = models.IntegerField(default=0)
def __str__(self):
return self.text
from django.db import models
class DataItem(models.Model):
text = models.CharField(max_length=200)
data = models.IntegerField(default=0)
def __str__(self):
return self.text
Register data in app_views/admin.py
from django.contrib import admin
from .models import DataItem
admin.site.register(DataItem)
from django.contrib import admin
from .models import DataItem
admin.site.register(DataItem)
from django.contrib import admin
from .models import DataItem
admin.site.register(DataItem)
Activate models
$ python manage.py makemigrations app_views
$ python manage.py sqlmigrate app_views 0001
$ python manage.py migrate app_views
$ python manage.py makemigrations app_views
$ python manage.py sqlmigrate app_views 0001
$ python manage.py migrate app_views
$ python manage.py makemigrations app_views
$ python manage.py sqlmigrate app_views 0001
$ python manage.py migrate app_views
Navigation / Redirection
Set root page of Django project
When accessing your Django project, the root page will normaly doesn’n show your app homepage.
To change this, you hate to modiy the url handling.
In the following sample, replace <appname> with the name of your app
Define a redirection view in your app (/<appname>/urls.py)
def redirect_to_home(request):
return redirect('/<appname>')
def redirect_to_home(request):
return redirect('/<appname>')
def redirect_to_home(request):
return redirect('/<appname>')
Define path in the global urls.py (/main/urls.py)
from django.contrib import admin
from django.urls import include, path
from django.shortcuts import redirect
from <appname> import views
path('', views.redirect_to_home, name='home'),
path('<appname>/', include('<appname>.urls')),
path('admin/', admin.site.urls)
from django.contrib import admin
from django.urls import include, path
from django.shortcuts import redirect
from <appname> import views
urlpatterns = [
path('', views.redirect_to_home, name='home'),
path('<appname>/', include('<appname>.urls')),
path('admin/', admin.site.urls)
]
from django.contrib import admin
from django.urls import include, path
from django.shortcuts import redirect
from <appname> import views
urlpatterns = [
path('', views.redirect_to_home, name='home'),
path('<appname>/', include('<appname>.urls')),
path('admin/', admin.site.urls)
]
Highlight current page in navigation menu
<div class="list-group">
<a href="{
Basic Upload
</a>
<a href="{
Progress Bar Upload
</a>
</div>
<div class="list-group">
<a href="{
Basic Upload
</a>
<a href="{
Progress Bar Upload
</a>
</div>
Using PostgresSQL Database
Install PostgresSQL
Create Superuser
createuser.exe --interactive --pwprompt
createuser.exe --interactive --pwprompt
createuser.exe --interactive --pwprompt
Logging
Additional reading
Tutorials
Testing
Blogs and Posts
Resolving problems
Wrong template is used
The template system is using a search approach to find the specified template file, e.g. ‘home.html’.
If you created more than one apps with the same filenames for templates, the first one will be used.
Change the template folders and add the app name, e.g.
template/
app_base/
home.html
template/
app_base/
home.html
Resolving error messages and erors
‘app_name’ is not a registered namespace
One reason for this error is the usage of a namespace in a link.
<p>If you want to use this way of links, you have to define the namespace/appname in your <code><app>/urls.py</code> file</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">app_name = 'app_views'
path('', views.HomeView.as_view(), name='home'),
]</pre><h3 class="wp-block-heading">dependencies reference nonexistent parent node</h3><ul class="wp-block-list"><li>Recreate database and migration files</li><li>Remove all migration files under */migrations/00*.py</li><li>Remove all pycache folders under */__pycache__ and */*/__pycache__</li><li>Run migration again</li></ul><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations
$ python manage migrate</pre><h3 class="wp-block-heading"><a href="https://stackoverflow.com/questions/43871604/valueerror-dependency-on-app-with-no-migrations-customuser">V</a>alueError: Dependency on app with no migrations: customuser</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations</pre><h2 class="wp-block-heading">Project Structure</h2><h3 class="wp-block-heading">Running tasks with Makefile</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">PREFIX_PKG := app
clearcache: # Clear Cache
python3 manage.py clearcache
python3 manage.py runserver 8000
rm -rf dist $(PREFIX_PKG)*
cd polls && python3 setup.py sdist
mkdir polls.dist && mv polls/dist/* polls/$(PREFIX_PKG)* polls.dist
install_bootstrap: # Install Bootstrap Library
cd .. && yarn add bootstrap
rm -rf polls/static/bootstrap
mkdir polls/static/bootstrap
cp -R ../node_modules/bootstrap/dist/* polls/static/bootstrap
install_jquery: # Install jQuery Library
rm -rf polls/static/jquery
mkdir polls/static/jquery
cp ../node_modules/jquery/dist/* polls/static/jquery
install_bootstrap_from_source: # Install Bootstrap from Source
wget https://github.com/twbs/bootstrap/releases/download/v4.1.3/bootstrap-4.1.3-dist.zip -O install/bootstrap-4.1.3-dist.zip && \
unzip install/bootstrap-4.1.3-dist.zip -d polls/static/bootstrap/4.1.3</pre>
Back to <a href="{
<p>If you want to use this way of links, you have to define the namespace/appname in your <code><app>/urls.py</code> file</p>
<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="1" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">app_name = 'app_views'
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
]</pre><h3 class="wp-block-heading">dependencies reference nonexistent parent node</h3><ul class="wp-block-list"><li>Recreate database and migration files</li><li>Remove all migration files under */migrations/00*.py</li><li>Remove all pycache folders under */__pycache__ and */*/__pycache__</li><li>Run migration again</li></ul><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations
$ python manage migrate</pre><h3 class="wp-block-heading"><a href="https://stackoverflow.com/questions/43871604/valueerror-dependency-on-app-with-no-migrations-customuser">V</a>alueError: Dependency on app with no migrations: customuser</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ python manage.py makemigrations</pre><h2 class="wp-block-heading">Project Structure</h2><h3 class="wp-block-heading">Running tasks with Makefile</h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">PREFIX_PKG := app
default:
grep -E ':\s+#' Makefile
clearcache: # Clear Cache
python3 manage.py clearcache
run: # Run Server
python3 manage.py runserver 8000
deploy: # Deploy
rm -rf dist $(PREFIX_PKG)*
rm -rf polls.dist
cd polls && python3 setup.py sdist
mkdir polls.dist && mv polls/dist/* polls/$(PREFIX_PKG)* polls.dist
install_bootstrap: # Install Bootstrap Library
cd .. && yarn add bootstrap
rm -rf polls/static/bootstrap
mkdir polls/static/bootstrap
cp -R ../node_modules/bootstrap/dist/* polls/static/bootstrap
install_jquery: # Install jQuery Library
cd .. && yarn add jquery
rm -rf polls/static/jquery
mkdir polls/static/jquery
cp ../node_modules/jquery/dist/* polls/static/jquery
install_bootstrap_from_source: # Install Bootstrap from Source
mkdir -p install && \
wget https://github.com/twbs/bootstrap/releases/download/v4.1.3/bootstrap-4.1.3-dist.zip -O install/bootstrap-4.1.3-dist.zip && \
unzip install/bootstrap-4.1.3-dist.zip -d polls/static/bootstrap/4.1.3</pre>
Back to <a href="{
If you want to use this way of links, you have to define the namespace/appname in your <app>/urls.py
file
path('', views.HomeView.as_view(), name='home'),
app_name = 'app_views'
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
]
app_name = 'app_views'
urlpatterns = [
path('', views.HomeView.as_view(), name='home'),
]
dependencies reference nonexistent parent node
- Recreate database and migration files
- Remove all migration files under */migrations/00*.py
- Remove all pycache folders under */__pycache__ and */*/__pycache__
- Run migration again
$ python manage.py makemigrations
$ python manage.py makemigrations
$ python manage migrate
$ python manage.py makemigrations
$ python manage migrate
ValueError: Dependency on app with no migrations: customuser
$ python manage.py makemigrations
$ python manage.py makemigrations
$ python manage.py makemigrations
Project Structure
Running tasks with Makefile
clearcache: # Clear Cache
python3 manage.py clearcache
python3 manage.py runserver 8000
rm -rf dist $(PREFIX_PKG)*
cd polls && python3 setup.py sdist
mkdir polls.dist && mv polls/dist/* polls/$(PREFIX_PKG)* polls.dist
install_bootstrap: # Install Bootstrap Library
cd .. && yarn add bootstrap
rm -rf polls/static/bootstrap
mkdir polls/static/bootstrap
cp -R ../node_modules/bootstrap/dist/* polls/static/bootstrap
install_jquery: # Install jQuery Library
rm -rf polls/static/jquery
mkdir polls/static/jquery
cp ../node_modules/jquery/dist/* polls/static/jquery
install_bootstrap_from_source: # Install Bootstrap from Source
wget https://github.com/twbs/bootstrap/releases/download/v4.1.3/bootstrap-4.1.3-dist.zip -O install/bootstrap-4.1.3-dist.zip && \
unzip install/bootstrap-4.1.3-dist.zip -d polls/static/bootstrap/4.1.3
PREFIX_PKG := app
default:
grep -E ':\s+#' Makefile
clearcache: # Clear Cache
python3 manage.py clearcache
run: # Run Server
python3 manage.py runserver 8000
deploy: # Deploy
rm -rf dist $(PREFIX_PKG)*
rm -rf polls.dist
cd polls && python3 setup.py sdist
mkdir polls.dist && mv polls/dist/* polls/$(PREFIX_PKG)* polls.dist
install_bootstrap: # Install Bootstrap Library
cd .. && yarn add bootstrap
rm -rf polls/static/bootstrap
mkdir polls/static/bootstrap
cp -R ../node_modules/bootstrap/dist/* polls/static/bootstrap
install_jquery: # Install jQuery Library
cd .. && yarn add jquery
rm -rf polls/static/jquery
mkdir polls/static/jquery
cp ../node_modules/jquery/dist/* polls/static/jquery
install_bootstrap_from_source: # Install Bootstrap from Source
mkdir -p install && \
wget https://github.com/twbs/bootstrap/releases/download/v4.1.3/bootstrap-4.1.3-dist.zip -O install/bootstrap-4.1.3-dist.zip && \
unzip install/bootstrap-4.1.3-dist.zip -d polls/static/bootstrap/4.1.3
PREFIX_PKG := app
default:
grep -E ':\s+#' Makefile
clearcache: # Clear Cache
python3 manage.py clearcache
run: # Run Server
python3 manage.py runserver 8000
deploy: # Deploy
rm -rf dist $(PREFIX_PKG)*
rm -rf polls.dist
cd polls && python3 setup.py sdist
mkdir polls.dist && mv polls/dist/* polls/$(PREFIX_PKG)* polls.dist
install_bootstrap: # Install Bootstrap Library
cd .. && yarn add bootstrap
rm -rf polls/static/bootstrap
mkdir polls/static/bootstrap
cp -R ../node_modules/bootstrap/dist/* polls/static/bootstrap
install_jquery: # Install jQuery Library
cd .. && yarn add jquery
rm -rf polls/static/jquery
mkdir polls/static/jquery
cp ../node_modules/jquery/dist/* polls/static/jquery
install_bootstrap_from_source: # Install Bootstrap from Source
mkdir -p install && \
wget https://github.com/twbs/bootstrap/releases/download/v4.1.3/bootstrap-4.1.3-dist.zip -O install/bootstrap-4.1.3-dist.zip && \
unzip install/bootstrap-4.1.3-dist.zip -d polls/static/bootstrap/4.1.3