Snippets Collections
virtualenv myenv

myenv\Scripts\activate

deactivate
{
    "python.defaultInterpreterPath": "E:\\WebDevDjango\\Django_Projects\\PARASenv\\Scripts\\Python.exe"
}
{% if places.spalte %}
	<section>
		{% render_elements "spalte" %}
	</section>
{% endif %}
    def create(self, validated_data):
        # print(validated_data)
        tags = validated_data.pop("tags")
        language = validated_data.pop("language")
        snip = Snip(**validated_data)
        # languageObj, created = Language.objects.get_or_create(**language)
        snip.language = language
        snip.save()
        for tag in tags:
            # tagObj, created = Tag.objects.get_or_create(**tag)
            # print(tagObj)
            snip.tags.add(tag)
        return ShallowSnipSerializer(snip).data
django-admin startproject mysite

python manage.py startapp myapp
{% include "cms/seminare.html" %}
if reg_form.is_valid():
            nuevo_usuario = reg_form.save(commit=False)
            pw_hash = bcrypt.hashpw(clave.encode(), bcrypt.gensalt()).decode() 
            nuevo_usuario.password = pw_hash
            nuevo_usuario.save()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'dojoreads_db',
        'USER': 'postgres',
        'PASSWORD': 'root',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}
# Git Commands

## git init
initialize git and create a new local repository

## git add .
track all the files in the local repo for changes

## git add filename
track a specific file in the repo for changes

## git commit -m "first commit" -m "the description"
take a snapshot of the files in the repo

## git status
check the status of your code

## git remote add origin https-link
add a new remote repository

## git push origin master
push the local repository to github

## git push -u origin master
push the local repository to github and also set upstream (enables you to use git push only in future)

## git branch
check the current branch and available branches

## git checkout -b new-branch-name
go to another new branch

## git checkout existing-branch
switch to an existing branch

## git diff feature
see the difference between files you want to merge

## git config --global user.name "[name]"
Sets the name you want attached to your commit transactions

## git config --global user.email "[email address]"
Sets the email you want attached to your commit transactions

## git config --global color.ui auto
Enables helpful colorization of command line output

## git push
use this cmd when pushing a new branch to see how it should be done

## git pull
when upstream is set , to pull from github when changes made on the github and want them to reflect on local machine

## git pull origin master
to pull from github when changes made on the github and want them to reflect on local machine

## git branch -d branch-name
delete a branch

## git commit -am "message"
commit and add at the same time
## generate the requirements file
pip freeze > requirements.txt

## specify where to store django static files just above the static url
STATIC_ROOT = BASE_DIR / 'staticfiles'

## tell heroku how to serve them with whitenoise
add this in settings.MIDDLEWARE below security
'whitenoise.middleware.WhiteNoiseMiddleware',

## add allowed hosts, name of app and local host url example
ALLOWED_HOSTS = ['text-test-heroku.herokuapp.com', '127.0.0.1:8000']

## create a runtime.txt file to put the python version required-
python-3.7.9

## create a Procfile file to say from where it would beserved
(make sure to have installed gunicorn in pip)
web: gunicorn MovieReview.wsgi --log-file -
MovieReview is folder where wsgi is located
//template

{% for contact in page_obj %}
    {# Each "contact" is a Contact model object. #}
    {{ contact.full_name|upper }}<br>
    ...
{% endfor %}

<div class="pagination">
    <span class="step-links">
        {% if page_obj.has_previous %}
            <a href="?page=1">&laquo; first</a>
            <a href="?page={{ page_obj.previous_page_number }}">previous</a>
        {% endif %}

        <span class="current">
            Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
        </span>

        {% if page_obj.has_next %}
            <a href="?page={{ page_obj.next_page_number }}">next</a>
            <a href="?page={{ page_obj.paginator.num_pages }}">last &raquo;</a>
        {% endif %}
    </span>
</div>
         

//views.py
         
from django.core.paginator import Paginator
from django.shortcuts import render

from myapp.models import Contact

def listing(request):
    contact_list = Contact.objects.all()
    paginator = Paginator(contact_list, 25) # Show 25 contacts per page.

    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    return render(request, 'list.html', {'page_obj': page_obj})       
{% if request.resolver_match.url_name == 'home' %} active {% endif %}
// template.html
<link rel="stylesheet" href="{% static '/bulma-css/bulma-divider.min.css' %}" type="text/css">
<link rel="stylesheet" href="{% static '/bulma-css/bulma-switch.min.css' %}" type="text/css"> 
<link rel="stylesheet" href="{% static '/bulma-css/bulma.min.css' %}" type="text/css"> 
<link rel="stylesheet" href="{% static '/css/main.css' %}" type="text/css"> 


// settings.py

STATIC_URL = '/static/'

STATIC_ROOT = 'avon/static'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static")
]

// views.py

def template(request, self):
	return render(request, "template.html")
    
//  urls.py

urlpatterns [] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

    
# make sure that you save the file when reloading changes in port 8000
# check the path you defined in views.py, and for urls.py


# views
def about(request):
    return render(request, 'about.html')
    
# urls

urlpatterns [
path('', views.index, name='index'),
path('templates/about.html/', views.about, name="about")
]
star

Thu Jul 29 2021 06:31:35 GMT+0000 (UTC)

#python #django
star

Thu Jul 29 2021 06:29:19 GMT+0000 (UTC) https://code.visualstudio.com/docs/python/environments

#python #django
star

Wed May 12 2021 08:30:51 GMT+0000 (UTC)

#python #django
star

Fri Apr 02 2021 12:37:15 GMT+0000 (UTC)

#python #django
star

Wed Mar 31 2021 10:03:05 GMT+0000 (UTC)

#django
star

Wed Mar 31 2021 00:23:18 GMT+0000 (UTC)

#django #python
star

Mon Mar 29 2021 22:20:07 GMT+0000 (UTC)

#python #django #postgres
star

Wed Dec 30 2020 19:26:24 GMT+0000 (UTC)

#django,python,django #django
star

Wed Dec 30 2020 19:24:10 GMT+0000 (UTC)

#django #python,django
star

Fri Dec 25 2020 11:34:54 GMT+0000 (UTC) https://stackoverflow.com/questions/38257231/how-can-i-upload-multiple-files-to-a-model-field

#django
star

Tue Dec 22 2020 11:16:09 GMT+0000 (UTC)

#python #django
star

Tue Dec 22 2020 09:02:28 GMT+0000 (UTC)

#python #django
star

Sun Aug 02 2020 02:24:12 GMT+0000 (UTC)

#django #css #html
star

Mon May 11 2020 13:44:16 GMT+0000 (UTC) https://stackoverflow.com/questions/15501673/how-to-temporarily-disable-a-foreign-key-constraint-in-mysql

#django #python

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension