Online store on Steemit blockchain| Step three | Create an application in a project

in Steem Alliance2 years ago (edited)

Hello, friends!

Step 03.jpg

Today we will create our first application in our project. And we will also change the project settings a little so that we can work on our computer. If this is not done, then we will not be able to work with static data and media.

We go to our project and click on the terminal and stop the server. Combination key Ctrl + C.

Screenshot_24.png

In the terminal, we then write a command to create our application:


python manage.py startapp market


where market is the name of our application.

Screenshot_32.png

In the config folder we find the settings file and add our application.

Screenshot_46.png

And we also immediately add certain settings so that we can work with the local server.

Here is the code to add. In the next post, I will add everything to git and you can easily follow the project.

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'


Screenshot_34.png

Also, os will be highlighted in red. You just need to click on os and import it.

Screenshot_35.png

Now we have to create a universal path to our application. This is pretty easy to do. We open a file called urls and add the path to our application there, as well as import the include function. The code looks like this:


from django.urls import path, include
path('', include('market.urls')),


Screenshot_36.png

In our market application, we create a python file called urls. In order to further prescribe our paths to different pages of our site.

Screenshot_37.png

Screenshot_39.png

After the urls file has been created, we prescribe urlpatterns and in the future it will prescribe the paths to our site pages.

from django.urls import path, include
from .import views

urlpatterns = [
]


Screenshot_51.png

Now we need to create a model of our product in order to carry out migrations and create a database. We write the model in the model file.

Screenshot_41.png

The model functions have already been imported, and we will work with it.

Screenshot_42.png

We need them in order to properly create a database.
You can read more about each Django feature on the site.

We carry out migrations and create a database.
Let's go to our project config.
Team:

cd config

Screenshot_44.png

Create a migration:

python manage.py makemigrations

Screenshot_45.png

The migration was successful. And the migration file was created. And also in the terminal, we saw which migrations were created for the database.

Screenshot_48.png

Now we create a database through migration.

Team: python manage.py migrate

Screenshot_49.png

We can see that the database has been created and everything is OK in the terminal.

Screenshot_50.png

In this post, we created our first application in our project and set the path to it. Also added settings in our project. So that you can work with static files and media. We also created a model of our product and made migrations. Then the database was created.

steem blockchain.jpg

You can get acquainted with the project here.

This is the first part: Step one
This is the second part: Step two

To be continued...

What do you think about the project? Will it be of interest to the community?
@rme ,
@rex-sumon , @shy-fox , @hungry-griffin, @pennsif


Sincerely, your @HardPhotographer

Sort:  

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.

Upvoted! Thank you for supporting witness @jswit.

Coin Marketplace

STEEM 0.19
TRX 0.16
JST 0.030
BTC 65904.42
ETH 2618.19
USDT 1.00
SBD 2.67