Академический Документы
Профессиональный Документы
Культура Документы
1. mkdir 'Website'
2. cd Website
3. mkdir 'PersonalWebsite'
4. cd PersonalWebsite
- .\scripts\activate
8. (For fresh start, in new PowerShell Windows begin the steps 2,4, and 6 again.)
(You can also look for Django version installed using the command 'pip freeze' in same path.)
# Creating Blank Django project
1. cd Website/PersonalWebsite
2. .\scripts\activate
Or
(Go to the project folder and inside src folder we type "python manage.py runserver" to run server in
PowerShell)
1. cd Website/PersonalWebsite
2. .\scripts\activate
1. cd Uthon/trydjango
2. .\scripts\activate
3. python manage.py startapp 'mysite' (we can create as many apps we need)
- mysite/static/mysite/images
def index(request):
if request.method == 'POST':
firstname = request.POST.get('fname')
lastname = request.POST.get('lname')
print(firstname)
json_data = json.loads(r.text)
joke = json_data.get('value').get('joke')
else:
firstname = 'Uttam'
lastname = 'Joshi'
print(firstname)
json_data = json.loads(r.text)
joke = json_data.get('value').get('joke')
def portfolio(request):
def contact(request):
if request.method == "POST":
email_r = request.POST.get('email')
subject_r = request.POST.get('subject')
message_r = request.POST.get('message')
c.save()
else:
- In mysite>urls.py:
urlpatterns = [
- And in PersonalWebsite>urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('mysite.urls')),
]
10. In mysite/models.py:
class Student(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
def __str__(self):
return self.first_name
class Contact(models.Model):
email = models.EmailField()
subject = models.CharField(max_length=196)
message = models.TextField()
def __str__(self):
return self.email
- And in terminal down there:
OR, in PowerShell:
cd Website/PersonalWebsite
scripts/activate
-In mysite/admin.py:
admin.site.register(Student)
admin.site.register(Contact)
Note: If we figured out any problem during Django, we simply delete 'mysite/migrations/0001_initial.py'
and 'db.sqlite3' folder but if we have numerous data we do not delete db.sqlite3.
- We have to use migration commands(will create deleted database folders again) again and
create superuser again if we deleted db.sqlite3 and 0001_initial folders respectively.
-Student.obejects.all()
-Contact.obejects.all()
NOTE2: We can also create object directly from the Powershell command:
-Student.objects.create(first_name='Danearys', last_name='Targerean')
a.save()
- Sample of base.htm, index.html, portfolio.html and contact.html codes:
-In mysite>templates>mysite>base.html:
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-
ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous">
<title>Dear World!</title>
</head>
<body>
</a>
<span class="navbar-toggler-icon"></span>
</button>
</li>
<li class="nav-item">
</li>
<li class="nav-item">
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item">
</a>
</li>
<li class="nav-item">
</a>
</li>
<li class="nav-item">
</a>
</li>
</ul>
</div>
</div>
</nav>
{% block content %}
{% endblock %}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-
UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
</body>
</html>
-In mysite>templates>mysite>index.html:
{% extends 'mysite/base.html' %}
{% block content %}
<div class="container">
<div class="col-sm-6">
{% csrf_token %}
</form>
</div>
<div class="col-sm-6">
<div class="card-body">
<p class="card-text">
{{ joker }}
</p>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
-In mysite>templates>mysite>portfolio.html:
{% extends 'mysite/base.html' %}
{% load static %}
{% block content %}
<div class="card-deck">
<div class="card">
<div class="card-body">
<h5 class="card-title">Unopinion</h5>
<p class="card-text">This is my startup whose aim is help Youtube content creators achieve
success..</p>
<p class="card-text">
<small class="text-muted">www.unopinion.com</small>
</p>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">FireFight</h5>
detection</p>
<p class="card-text">
</p>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">Kupika</h5>
<p class="card-text">Smart Container for Babies - IOT based Application and hardware</p>
<p class="card-text">
</p>
</div>
</div>
</div>
</div>
{% endblock %}
-In mysite>templates>mysite>contact.html:
{% extends 'mysite/base.html' %}
{% block content %}
<div class="container">
<div class="row">
{% csrf_token %}
<div class="col-10">
</div>
</div>
<div class="col-10">
</div>
</div>
<div class="col-10">
</div>
<div class="pull-right">
</div>
</form>
</div>
</div>
</div>
{% endblock %}
- In mysite/templates/mysite/thank.html:
{% extends 'mysite/base.html' %}
{% block content %}
{% endblock %}