Get Public IP Address
(Invoke-WebRequest ifconfig.me/ip).Content.Trim()
Get Public IP Address
(Invoke-WebRequest ifconfig.me/ip).Content.Trim()
Make Virtual Hosts, Lets Encrypt
with open('/etc/db_pass.txt') as g:
DB_PASS = g.read().strip()
Make sure hkhtmltopdf is installed in /usr/bin/wkhtmltopdf
Install Requirements.txt
Django 2.2
Pip install PDF kit https://pypi.org/project/pdfkit/
pip install pdfkit
sudo apt-get install wkhtmltopdf
pip install django-wkhtmltopdf
Install xlsxwriter
pip install xlsxwriter
chown -R $USER:$USER /directory
chmod -R 775 /directory
Back up a database
mysqldump -u [username] –p[password] [database_name] > [dump_file.sql]
Restore a database
mysql -u [username] –p[password] [database_name] < [dump_file.sql]
Search Command:
dir /s /b filename
The /s command allows you to view all files of a certain type within all subsequent folders of your current path. You can search for a specific file, as in the example above, or use a wildcard ‘*’ to view all files of a certain type. The below example will search for all pdf files within your current directory and all subsequent folders of your current path.
dir /s /b *.pdf
Install xlsxwriter
#pip install XlsxWriter
Or follow instructions here: https://xlsxwriter.readthedocs.io/getting_started.html
Imports
import io
from xlsxwriter.workbook import Workbook
from django.http import HttpResponse
views.py
def download_excel_view(request, object_id):
object = Model.objects.get(object_id=object_id)
output = io.BytesIO()
workbook = Workbook(output, {'in_memory': True})
worksheet = workbook.add_worksheet()
worksheet.write(0, 0, 'Hello, world!')
workbook.close()
output.seek(0)
response = HttpResponse(output.read(), content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
response['Content-Disposition'] = "attachment; filename=excelsheetname.xlsx"
output.close()
return response
urls.py
from django.urls import path
from . import views
app_name = "excelwriter"
urlpatterns = [
### other views
path("download-excel-sheet", views.download_excel_view, name="download_sheet"),
]
Template HTML
<a href="{% url 'excelwriter:download_sheet' object_id %}" >
<button class="btn btn-lg btn-dark button" style="width:100%">
<span>Download Turnover Doc</span></button> </a>
Step 1: Create User
mysql > CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Step 2: Grant Privileges
mysql > GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
Step 3: Flush Privileges
mysql > FLUSH PRIVILEGES;
If you are having trouble accessing your mysql shell through your command prompt, you will have to add it to your PATH environment variable.