create account

Create a forum application using django #4: Admin dashboard ang setting redirect by duski.harahap

View this thread on: hive.blogpeakd.comecency.com
· @duski.harahap ·
$23.87
Create a forum application using django #4: Admin dashboard ang setting redirect
#### Repository
https://github.com/python

#### What Will I Learn?
- Admin dashboard
- Settings redirect

#### Requirements
- Basic Python
- Install Python 3
- Install Django


#### Resources
- Python - https://www.python.org/
- Django- https://www.djangoproject.com/
- Bootstrap 4 - https://getbootstrap.com/docs/4.0/getting-started/introduction/

#### Difficulty
Basic

### Tutorial Content

Hi everyone, this is an advanced tutorial from the previous tutorial series. In this application, we will learn how to create a forum using Django. in the previous tutorial, I created an authentication system and template system that uses a class-based view. Well in this section of the tutorial we will discuss a new feature that is an important part of this application, namely the admin system, of course, if we want to create a forum application we must create an admin system to manage the content in our application. For that, we just start this tutorial.


### Make admin dashboard

To know **Django** provides an admin dashboard that is ready to use, but there needs to be something that must be configured when we want to use this feature. to start using it we need to manage who can use this dashboard.

- **Create superuser**

to make the **superuser** we will make it through the command prompt. later the user will have access to manage the admin. You can open a command prompt and access manage.py as we can see in the picture below:

![Screenshot_1.png](https://ipfs.busy.org/ipfs/QmeyNHRfrY9tPKNLmwZyi7r8TUYWewrL2hfmDX62togtLB)

We have created a superuser to access the dashboard page, you can go back to the command prompt page and run your server. as we see in the picture below:

![ezgif.com-video-to-gif.gif](https://cdn.steemitimages.com/DQmaJiBALQHbfbV5MpunU8DmVJqcuwnZMgbWodXh1VPQ6aY/ezgif.com-video-to-gif.gif)
<br>

- **Access the admin dashboard**

After we run the server, then we will access the admin dashboard and log in with the user that we have created as a **superuser**. The following is the admin dashboard:

![Screenshot_2.png](https://ipfs.busy.org/ipfs/QmY63T4LzWLAMVYFN8dEN2NseWWihBLW2g6NHzhwCotqsx)

The superuser we have registered in the previous section is **Millea** and we will log in with that user. we can see the demonstration in the picture below:

![ezgif.com-video-to-gif (1).gif](https://cdn.steemitimages.com/DQmWJAdFxqMeHZgzBtTb9D79bPKdmDBfteUNmJNNKX5rnXi/ezgif.com-video-to-gif%20(1).gif)

Now you can see in the picture above we have successfully entered the admin dashboard.
<br>
- **Setting redirect**

There is a part that will be changed in this tutorial, in Django we can set the redirect to the page we want. we can do this in the **settings.py** section.

**settings.py**
```
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

LOGOUT_REDIRECT_URL = '/account/login'         //redirect when logout

```

We will redirect the page when we log out. If there is no error then we can get the results as follows:

![ezgif.com-video-to-gif (2).gif](https://cdn.steemitimages.com/DQmcs1AKsgmXM6V6yqhThua1ZVDXrf3JqCbDL45hpwcw6Tq/ezgif.com-video-to-gif%20(2).gif)
<br>

Then I will create a filter menu that will be displayed on the menu in the Navbar. The logout menu will only appear when the user is logged in. For more details, we can look at **base.html** below:

**base.html**

```
	<ul class="navbar-nav mr-auto">
	      <li class="nav-item active">
	        <a class="nav-link" href="">Home <span class="sr-only">(current)</span></a>
	      </li>
		{% if user.is_authenticated %}
	      <li class="nav-item">
	      	<a class="nav-link" href="{% url 'logout' %}">Logout</a>
	      </li>
	    {% else %}
	      <li class="nav-item">
	        <a class="nav-link" href="{% url 'signup' %}">Register</a>
	      </li>
	      <li class="nav-item">
	        <a class="nav-link" href="{% url 'login' %}">Login</a>
	      </li>
	    {% endif %}
    </ul>
```

- We can check whether the user is logged in or not by checking the **is_authenticated** value, The value is ***boolean***, so we can use it like this ```	{% if user.is_authenticated %}```.
<br>
- **Create welcome page**

Now we will make a welcome page that will be used for the home page. we will create a new page that is **welcome.html** which will become the home page. here is the code:

**welcome.html**

```
{% extends "base.html" %}

{% block title %} Sign in{% endblock %}

{% block content %}
<div class="jumbotron">
  <h1>Forum Apps</h1> 
  <p>Welcome to landing page</p> 
</div>
{% endblock%}
```
on the homepage I will use jumbotron from the boostrap to make the homepage appear

**Routing home page**

Of course, we will also provide routing for the homepage page that was created. we can make it **urls.py** page.
**urls.py**

```
from django.contrib import admin
from django.urls import path, include
from django.views.generic import TemplateView // import generic view

urlpatterns = [
	  path(' ', TemplateView.as_view(template_name='welcome.html')),
    path('admin/', admin.site.urls),
    path('account/', include('account.urls')),
    path('account/', include('django.contrib.auth.urls')),
]

```

- As we learned in the previous [tutorial](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-2-template-system-and-class-based-view-implementation-1552057536737), we will use generic view, a function provided by Django to create a view. to use this function we will import it first as follows ```from django.views.generic import TemplateView```.

- And then to use it we can write it like the following ``` path(' ',TemplateView.as_view(template_name='welcome.html')),```. We can use **TemplateView** because we have already name it when importing. We adjust the view that will be rendered on **template_name**.

**Settings redirect**

Then I will do a redirect setting for users who have successfully logged in to redirect the home page. for that I will add it in **settings.py**.

```
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

LOGOUT_REDIRECT_URL = '/account/login'
LOGIN_REDIRECT_URL = '/'  ## Redirect to homepage
```

If there is no error then we can see when logging in, we will be directed to the **homepage**:

![ezgif.com-video-to-gif (3).gif](https://cdn.steemitimages.com/DQmfMJdXzfgYRTiZN1YYp3T8x4WYTcGYkdocZoCRLGEEaDE/ezgif.com-video-to-gif%20(3).gif)

We can see in the picture above we managed to make a page redirect and create a function to access the admin dashboard in the application that we created. we have added some features. Of course there are still some features that we will add, but I will discuss them in the next tutorial, hopefully, this tutorial will be useful for you.


### Curriculum

- **Class-based views**

[Tutorial Django - Class based views #1 : Installation and configuration Django, Using a template system](https://steemit.com/utopian-io/@duski.harahap/django-tutorial-class-based-view-1-installation-and-configuration-django-using-a-template-system-1545837443632)

[Tutorial Django - Class based view #2 : Use Class based view method and Get and Post method](
https://steemit.com/utopian-io/@duski.harahap/django-tutorial-class-based-view-2-use-class-based-view-method-and-get-and-post-method-1546448948207)

[Tutorial Django- Class based view #3 : Authentication in Django and Urls Protection globally and specifically](
https://steemit.com/utopian-io/@duski.harahap/django-tutorial-class-based-view-3-authentication-in-django-and-urls-protection-globally-and-specifically-1546614192675)
<br>
- **Forum app**

[Create a forum application using django #1 : Init projects and dependencies and Database schema](
https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-1-init-projects-and-dependencies-and-database-schema-1551711163679)

[Create a forum application using django #2: Template system and Class-based view implementation](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-2-template-system-and-class-based-view-implementation-1552057536737)


#### Proof of work done

https://github.com/milleaduski/forums-django
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 55 others
properties (23)
authorduski.harahap
permlinkcreate-a-forum-application-using-django-4-admin-dashboard-ang-setting-redirect
categoryutopian-io
json_metadata{"tags":["utopian-io","tutorials","python","web","django"],"image":["https://ipfs.busy.org/ipfs/QmeyNHRfrY9tPKNLmwZyi7r8TUYWewrL2hfmDX62togtLB","https://cdn.steemitimages.com/DQmaJiBALQHbfbV5MpunU8DmVJqcuwnZMgbWodXh1VPQ6aY/ezgif.com-video-to-gif.gif","https://ipfs.busy.org/ipfs/QmY63T4LzWLAMVYFN8dEN2NseWWihBLW2g6NHzhwCotqsx","https://cdn.steemitimages.com/DQmWJAdFxqMeHZgzBtTb9D79bPKdmDBfteUNmJNNKX5rnXi/ezgif.com-video-to-gif%20(1).gif","https://cdn.steemitimages.com/DQmcs1AKsgmXM6V6yqhThua1ZVDXrf3JqCbDL45hpwcw6Tq/ezgif.com-video-to-gif%20(2).gif","https://cdn.steemitimages.com/DQmfMJdXzfgYRTiZN1YYp3T8x4WYTcGYkdocZoCRLGEEaDE/ezgif.com-video-to-gif%20(3).gif"],"links":["https://github.com/python","https://www.python.org/","https://www.djangoproject.com/","https://getbootstrap.com/docs/4.0/getting-started/introduction/","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-2-template-system-and-class-based-view-implementation-1552057536737","https://steemit.com/utopian-io/@duski.harahap/django-tutorial-class-based-view-1-installation-and-configuration-django-using-a-template-system-1545837443632","https://steemit.com/utopian-io/@duski.harahap/django-tutorial-class-based-view-2-use-class-based-view-method-and-get-and-post-method-1546448948207","https://steemit.com/utopian-io/@duski.harahap/django-tutorial-class-based-view-3-authentication-in-django-and-urls-protection-globally-and-specifically-1546614192675","https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-1-init-projects-and-dependencies-and-database-schema-1551711163679","https://github.com/milleaduski/forums-django"],"app":"steemit/0.1","format":"markdown"}
created2019-03-13 14:50:54
last_update2019-03-13 14:50:54
depth0
children4
last_payout2019-03-20 14:50:54
cashout_time1969-12-31 23:59:59
total_payout_value18.152 HBD
curator_payout_value5.714 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length8,261
author_reputation60,094,717,098,672
root_title"Create a forum application using django #4: Admin dashboard ang setting redirect"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,232,345
net_rshares34,889,213,448,123
author_curate_reward""
vote details (119)
@portugalcoin ·
$11.84
Thank you for your contribution @duski.harahap.
After analyzing your tutorial we suggest the following points below:

- We suggest that you take more care when writing your contribution. For the tutorial to be well understood for the reader needs to be well written.

- Your tutorial is quite short for a good tutorial. We recommend you aim for capturing at least 2-3 concepts.

- Having GIFs instead of images makes your tutorial more intuitive. Good job!

- We suggest you add more features to your tutorial. 

Looking forward to your upcoming tutorials.

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/8/3-1-1-1-1-4-2-3-).

---- 
Need help? Chat with us on [Discord](https://discord.gg/uTyJkNm).

[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , , , , , , ,
properties (23)
authorportugalcoin
permlinkre-duskiharahap-create-a-forum-application-using-django-4-admin-dashboard-ang-setting-redirect-20190313t222605144z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["duski.harahap"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/8/3-1-1-1-1-4-2-3-","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2019-03-13 22:26:06
last_update2019-03-13 22:26:06
depth1
children1
last_payout2019-03-20 22:26:06
cashout_time1969-12-31 23:59:59
total_payout_value8.990 HBD
curator_payout_value2.854 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,008
author_reputation599,460,589,822,571
root_title"Create a forum application using django #4: Admin dashboard ang setting redirect"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,261,229
net_rshares17,443,473,559,888
author_curate_reward""
vote details (16)
@utopian-io ·
Thank you for your review, @portugalcoin! Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-duskiharahap-create-a-forum-application-using-django-4-admin-dashboard-ang-setting-redirect-20190313t222605144z-20190316t045718z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-03-16 04:57:21
last_update2019-03-16 04:57:21
depth2
children0
last_payout2019-03-23 04:57:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length64
author_reputation152,955,367,999,756
root_title"Create a forum application using django #4: Admin dashboard ang setting redirect"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,392,321
net_rshares0
@steem-ua ·
#### Hi @duski.harahap!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-create-a-forum-application-using-django-4-admin-dashboard-ang-setting-redirect-20190313t225630z
categoryutopian-io
json_metadata"{"app": "beem/0.20.18"}"
created2019-03-13 22:56:33
last_update2019-03-13 22:56:33
depth1
children0
last_payout2019-03-20 22:56:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length292
author_reputation23,214,230,978,060
root_title"Create a forum application using django #4: Admin dashboard ang setting redirect"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,262,825
net_rshares0
@utopian-io ·
Hey, @duski.harahap!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-create-a-forum-application-using-django-4-admin-dashboard-ang-setting-redirect-20190314t050554z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-03-14 05:05:57
last_update2019-03-14 05:05:57
depth1
children0
last_payout2019-03-21 05:05:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length595
author_reputation152,955,367,999,756
root_title"Create a forum application using django #4: Admin dashboard ang setting redirect"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,279,986
net_rshares0