본문 바로가기

TIL

TIL 062923

https://stackoverflow.com/questions/34446415/joining-functions-onclick-and-onkeyup

 

joining functions onclick and onkeyup

I just went over my code with an experienced developer and he made a lot of very helpful changes, but, unfortunately, the code did not save properly and I lost all the edits!!! The main thing he h...

stackoverflow.com

https://88240.tistory.com/52

 

[JavaScript] input에 입력 후 enter쳐서 submit하기

input 박스가 하나일경우 submit 버튼을 마우스로 클릭하지 않고 enter를 쳐도 submit버튼을 누른 효과를 낼 수 있다. 하지만 input창이 2개 이상이 되었을 경우 Enter 효과는 먹히지 않는다. 요번엔 ID와 PW

88240.tistory.com

https://charliecharlie.tistory.com/233

 

[JavaScript] 값 입력 후 엔터(Enter)키 눌렀을 때 이벤트 실행

로그인 시 ID/PW 입력 후 굳이 마우스로 로그인 버튼을 클릭하지 않고 엔터만 눌러도 로그인 이벤트가 실행된다. 이와 유사한 이벤트를 만들어 보자. 전체코드 - onkeypress는 키보드의 키를 눌렀을

charliecharlie.tistory.com

https://blog.miyam.net/139

 

Javascript에서 엔터(Enter) 키 이벤트

입력후 엔터(Enter) 키를 눌렀을 때 이벤트를 발생하고 싶을 경우에 사용하면 된다. 예로 로그인 할때 패스워드를 입력하고 엔터를 눌렀을 때 로그인을 해야 될 때 1. 이벤트 발생시 수행할 함수를

blog.miyam.net

https://coding-restaurant.tistory.com/233

 

[JS] onchange, onkeydown, onkeyup 정리

onchange : Html의 요소가 바뀌었을 때 (텍스트입력칸 변경 등) onclick : 유저가 Html의 요소를 클릭했을 때 onmouseover : 유저가 마우스를 html 요소로 올렸을 때 onmouseout : 유저가 마우스를 html 요소 밖으로

coding-restaurant.tistory.com

https://sir.kr/pg_tip/11229

 

onclick 과 onkeyup을 하나의 변수에 동시에 사용하면 안되는 건가요? > SIR

라디오버튼으로 숫자를 선택하면 아래에 그래프로 표시되도록 구현했는데요,이 부분은 잘 작동합니다.그런데 여기에서 텍스트박스에 직접 입력하기를 함께 사용하려고 하는데 직접입력 부분

sir.kr

https://velog.io/@taemindev/onKeyUp-onClick-KeyCode13

 

onKeyUp , onClick, KeyCode13

아주간단한 예제를 통해서onKeyUp도 사용해보고onClick도 사용해보고keyCode13이라는 것을 이용해서 클릭하지 않고 엔터만눌러서submit을 해보자일단 예제코드는 아래와 같다이벤트 e를 괄호안에 넣어

velog.io

메인 페이지에서 장소 검색 시 엔터키로 검색 버튼을 실행할 수 있었으면 좋겠다는  피드백이 들어왔다.

나도 똑같이 느꼈지만 다른 부분이 더 급하고 중요하다고 생각해서 넘어갔었는데 피드백이 들어온 김에 검색해봤다.

자바스크립트에선 13이 엔터키라고 한다.


https://stackoverflow.com/questions/5113374/javascript-check-if-variable-exists-is-defined-initialized

 

JavaScript check if variable exists (is defined/initialized)

Which method of checking if a variable has been initialized is better/correct? (Assuming the variable could hold anything (string, int, object, function, etc.)) if (elem) { // or !elem or if (typeof

stackoverflow.com

로그인하지 않고 누군가의 마이페이지에 접근 불가능한 현상 발견.

access token과 payload가 localstorage에 없으면 그 다음 코드들이 모두 실행되지 않고 에러가 났다.

자기 자신의 마이페이지에 접근하는건지 다른 사람의 마이페이지에 접근하는건지만 구분하고 localstorage에 아무것도 없는 경우를 빼먹었다.

그 부분을 수정하면서 ismymypage가 정의되지 않았다면 프로필 수정, 회원 탈퇴, 팔로우/언팔로우 이런 버튼들이 모두 보이지 않도록 하기위해 검색해봤다.

 

if (typeof variable === 'undefined' || variable === null) {
    // variable is undefined or null
}

 

typeof를 이용하여 확인 가능!


https://kth990303.tistory.com/168

 

[VanillaJS] html 태그를 선택하는 querySelector에 대해 알아보자

사실 프론트 프레임워크를 다룬다면 querySelector는 거의 쓰이지 않지만, 바닐라js를 다룬다면 꽤나 자주 보게 될 querySelector에 대해 알아보자. 프론트 프레임워크를 배울거라고 querySelector 안배우겠

kth990303.tistory.com

getElementById 말고 querySelector로 요소를 가져오려 했는데 html파일에 없고 js에서 innerHTML이나 creatElement로 만든 후 appendChild해준 요소는 querySelector로 선택하지 못하는 것 같다.


faker.coordinate(): 좌표

faker.longitude(): 경도

faker.latitude(): 위도


https://velog.io/@rimi0108/Django-DateTime-%ED%99%9C%EC%9A%A9%EB%B2%95

 

[Django] DateTime 활용법

DateTime 이용해 원하는 데이터, 원하는 형식으로 시간과 날짜 출력하기

velog.io

테스트 코드에서 이미지나 날짜가 이상할 때 str()로 감싸주면 많은 경우 해결된다.


https://ofcourse.kr/css-course/float-%EC%86%8D%EC%84%B1

 

CSS float 속성 - ofcourse

개요 float 라는 단어는 원래 ‘뜨다’ 라는 의미이며, 원래 웹페이지에서 이미지를 어떻게 띄워서 텍스트와 함께 배치할 것인가에 대한 속성입니다. inherit: 부모 요소에서 상속 left: 왼쪽에 부유

ofcourse.kr

핸드폰으로 보는 화면 모드에서 검색바에 float:right;가 적용되어 있어서 이상하게 나왔었는데 float:none;으로 덮어씌워줘서 해결했다.


https://stackoverflow.com/questions/34989915/write-only-read-only-fields-in-django-rest-framework

 

Write only, read only fields in django rest framework

I have models like this: class ModelA(models.Model): name = models.CharField() class ModelB(models.Model): f1 = models.CharField() model_a = models.ForeignKey(ModelA) Serializers: c...

stackoverflow.com

write only: 비밀번호에 쓰임. 볼 수 없게, 하지만 만들거나 수정은 할 수 있게

read only: 반대. 보기만 가능하게. 이메일 등.

extra kwargs로 개별 설정


https://stackoverflow.com/questions/13202385/django-reverse-with-arguments-and-keyword-arguments-not-found

 

Django Reverse with arguments '()' and keyword arguments '{}' not found

Hi I have an infuriating problem. I have a url pattern like this: # mproject/myapp.urls.py url(r'^project/(?P<project_id>\d+)/$','user_profile.views.EditProject',name='edit_project'), it ...

stackoverflow.com

https://stackoverflow.com/questions/69540162/how-to-use-reverse-with-optional-parameters-in-django

 

How to use reverse with optional parameters in django?

I have the below URL in which I pass an integer value (pk) now when I am calling reverse on this URL I am getting the below-mentioned error. urls.py urlpatterns = [ path('batch-postpone/<in...

stackoverflow.com

https://docs.djangoproject.com/en/4.2/topics/testing/tools/

 

Django

The web framework for perfectionists with deadlines.

docs.djangoproject.com

 

https://stackoverflow.com/questions/25864935/pass-a-query-parameter-with-django-reverse

 

Pass a query parameter with django reverse?

I have a url that is meant to be accessed like /people/raj/updates /people/raj/updates?tag=food But Django reverse URL resolver seems to have no provision to do tag=food, that is to detect it as an

stackoverflow.com

https://stackoverflow.com/questions/61757651/test-in-django-reverse-with-no-arguments-not-found

 

Test in Django, reverse with no arguments not found

I want to test two views in Django: class TestSubstitute(TestCase): def test_Substitute(self): url = reverse('finder:substitute') url_with_param = "{}/{}/".format(url, 1) ...

stackoverflow.com

https://stackoverflow.com/questions/9585491/how-do-i-pass-get-parameters-using-django-urlresolvers-reverse

 

How do i pass GET parameters using django urlresolvers reverse

I am using django 1.2 and going from one view to another using the urlresolvers reverse method. url = reverse(viewOne) and I want to pass a get parameter, for example name = 'joe' so that in...

stackoverflow.com

https://gist.github.com/benbacardi/227f924ec1d9bedd242b

 

Django reverse with a querystring

Django reverse with a querystring. GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

https://stackoverflow.com/questions/63553515/django-can-i-reverse-a-parameterized-url-without-passing-any-arguments

 

Django can i reverse a parameterized url without passing any arguments?

app_name = 'app_name' path('url/<uuid:uuid>',someview.as_view(),name='somename') def get_url(): return reverse('app_name:somename',args=None) I want get_url to return 'url/' Is it possib...

stackoverflow.com

https://stackoverflow.com/questions/73535678/error-when-reverse-url-with-multiple-arguments-django

 

Error when reverse url with multiple arguments - Django

I'm writing a test for an url, problem is it fails when I try to pass multiple arguments, here is some code: #test_urls.py from django.test import SimpleTestCase from django.urls import reverse, re...

stackoverflow.com

테스트 코드 작성 시 url을 reverse를 써서 이름으로 가져오는걸 수업으로 배우고 썼었다.

get absolute url로 article이나 user, review등의 id를 url에 넣을 수 있었다.

그런데 이번에 django-filter, searchfilter, pagination로 물음표를 사용한 url을 새로 쓰게 되었다.

이때 테스트 코드 작성 시 reverse를 이용해 이름으로 가져온 url에 어떻게 파라미터를 넣는건지 검색해봤는데 간단한 방법은 못 찾았다.

직접 "?page=2" 이런 문자열을 추가해주거나 def reverse_querystring() 이렇게 새로 함수를 만들어서 쓰거나 reverse를 쓰지 않는 방법이 있었다.


The key-value pairs in the data dictionary are used to create a GET data payload. For example:

>>> c = Client()
>>> c.get("/customers/details/", {"name": "fred", "age": 7})
…will result in the evaluation of a GET request equivalent to:

/customers/details/?name=fred&age=7

 

url이 바뀔 가능성이 적기 때문에 장고 공식 문서대로 reverse를 쓰지 않는 방법으로 테스트 코드를 작성했다.


https://stackoverflow.com/questions/2217488/age-from-birthdate-in-python

 

Age from birthdate in python

How can I find an age in python from today's date and a persons birthdate? The birthdate is a from a DateField in a Django model.

stackoverflow.com

부등식 명제가 참이면 1, 거짓이면 0의 값을 가지는 것을 이용해 생년월일로부터 나이를 계산하기.

from datetime import date

def calculate_age(born):
    today = date.today()
    return today.year - born.year - ((today.month, today.day) < (born.month, born.day))


spot 정보를 get 요청할 때 related_name인 spot_reviews를 이용해서 그 spot의 review들을 pagination을 적용하면서 가져오고 싶어서 검색해봤다.

https://stackoverflow.com/questions/21083018/paginated-result-for-related-field-in-django

 

paginated result for related field in django?

Suppose I have the following models. Class Blog: pass class Entry: models.ForeignKey(Blog) I want to do something like this filter & sort blog by some criteria get related entrie...

stackoverflow.com

https://stackoverflow.com/questions/72374901/how-to-do-pagination-for-a-serializer-field

 

How to do pagination for a serializer field?

I have a task where I need to get stats and feedback by moderator ID. The 'stats' field is general, the 'feedback' field is a list of feedbacks. Can I make pagination for 'feedback' field? Of cours...

stackoverflow.com

https://github.com/encode/django-rest-framework/issues/756

 

Paginate related fields? · Issue #756 · encode/django-rest-framework

We are using DRF for our API & loving it so far! However, we have a need to paginate relationship fields that return multiple items - couldn't find a way to do this. To demonstrate using examples s...

github.com

https://stackoverflow.com/questions/72771164/how-to-properly-display-all-inline-fields-associated-with-its-parent-model-field

 

How to properly display all inline fields associated with its parent model fields when paginating in Django template?

I'm a student and a Django newbie, and we have a project that we're trying to build using Django. In my journey to building the project I stumbled upon a problem and got stuck for weeks now. I want...

stackoverflow.com

https://docs.djangoproject.com/en/dev/topics/pagination/?from=olddocs 

 

Django

The web framework for perfectionists with deadlines.

docs.djangoproject.com

https://stackoverflow.com/questions/10518879/does-django-comments-support-pagination

 

Does django comments support pagination?

I wonder is it possible to only display for example the 10 latest comments on the page. And then the user can click, on demand, if he wants to view more comments? I was unsure what to search for

stackoverflow.com

https://stackoverflow.com/questions/24020174/django-comments-pagination-isnt-working

 

Django comments pagination isnt working

there is a trouble I'm new to django and there is an issue I can't understand, there is a view: def article(request, article_id = 1, comments_page_number = 1): all_comments = Comments.objects.

stackoverflow.com

https://stackoverflow.com/questions/68802319/how-to-apply-pagination-in-this-case-django-rest-framework

 

How to apply pagination in this case (Django Rest Framework)?

I built a simple social media application. Users can post two types of posts Blog and Carousel. Users can follow other users, you can see other users posts if you follow them. So, while implementin...

stackoverflow.com

https://stackoverflow.com/questions/76117448/in-django-rest-framework-drf-how-to-do-pagination-when-we-are-getting-page-num

 

In Django Rest Framework (DRF) how to do pagination when we are getting page number from request body?

Generally, when we use pagination in Django Rest Framework (DRF), from URL we are sending parameters like some-url/?page=2&page_size=50 Now, in my case, I'm sending a request with those paramet...

stackoverflow.com

https://freekim.tistory.com/11

 

[Django] RestFramework Pagination 예제

서버로부터 데이터를 받아올 때 한번에 다 받아올 수도 있지만 데이터가 많을 경우 일부분만 받아와야 할 경우가 생긴다. 예를 들면 대부분의 홈페이지에 게시판을 보더라도 한번에 모든 글들

freekim.tistory.com

https://stackoverflow.com/questions/1028229/django-paginated-comments-is-there-any-existing-solutions

 

Django Paginated Comments .. is there any existing solutions?

is there any existing pagination solution for Django contrib.comments? What I need is just a simple paginated django comments, for the Basic Blog application (from the Django Basic Apps) I used, u...

stackoverflow.com

https://stackoverflow.com/questions/21381700/django-rest-framework-how-do-you-flatten-nested-data/37657376#37657376

 

django rest framework - how do you flatten nested data?

I have a 'through' model governing a many to many relationship and i want to be able to return the 'through' model and the target model as flat data, as opposed to having the target model nested. So

stackoverflow.com

https://stackoverflow.com/questions/57635354/django-pagination-on-model-with-foreign-key

 

Django pagination on model with foreign key

Post and comment models class Post(models.Model): title = models.CharField(max_length=120) content = models.TextField() class Comment(models.Model): post = models.ForeignKey(Post, on_...

stackoverflow.com

https://github.com/alanjds/drf-nested-routers

 

GitHub - alanjds/drf-nested-routers: Nested Routers for Django Rest Framework

Nested Routers for Django Rest Framework. Contribute to alanjds/drf-nested-routers development by creating an account on GitHub.

github.com

https://www.django-rest-framework.org/api-guide/routers/

 

Routers - Django REST framework

 

www.django-rest-framework.org

https://stackoverflow.com/questions/43697659/paginating-foreign-key-relations

 

Paginating foreign key relations

class Foo(models.Model): pass class Bar(models.Model): foo = models.ForeignKey(Foo, related_name="bars") If a Foo has thousands of Bars, a generic HyperlinkedModelSerializer will render t...

stackoverflow.com

https://stackoverflow.com/questions/60175087/apply-sorting-on-field-in-foreign-key-django-rest-framework

 

Apply sorting on field in foreign key django rest framework

I have three models: Class Book(models.Model): book_name = models.CharField(max_length=10) author = models.Foreignkey('author', on_delete=models.cascade) Class Author(models.Model): name = models.

stackoverflow.com


import requests나 request가 해결책은 아닌 것 같다.


https://velog.io/@meekukin/TIL-django

 

[Python] request.GET / request.GET.get()

request.GET은 GET으로 받는 인자들을 다 포함하는 딕셔너리 객체이다. get() 메서드는 키값이 딕셔너리 안에 있으면 밸류값을 리턴해준다. 키값이 존재하지 않으면 디폴트값 None을 리턴한다. request.GE

velog.io

https://stackoverflow.com/questions/56927894/paginate-comments-to-posts

 

Paginate comments to Posts

I have a comment form for my posts. It looks like this view.py def add_comment_to_post(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == "POST": form =

stackoverflow.com

https://stackoverflow.com/questions/58036836/drf-paginate-foreign-key-field

 

DRf, paginate foreign key field

I wanna do something like below, but the code as it is inefficient, How can I return paginated response of related object? class Bar(models.Model): pass class Foo(models.Model): bar = ...

stackoverflow.com

https://stackoverflow.com/questions/69877308/paginating-django-view-with-foreign-key-data

 

Paginating Django View with Foreign Key Data

I'm trying to build a simple Django gallery that allows photos to be added to an album. Everything thus far is working fine (upload photo, add to album, paginated all photos listing, photo details/

stackoverflow.com

https://stackoverflow.com/questions/15617595/paginate-relationship-in-django-rest-framework

 

Paginate relationship in Django REST Framework?

We are using Django REST Framework for our API and we have a need to paginate relationship fields that return multiple items. To demonstrate using examples similar to those in the documentation: ...

stackoverflow.com

모르겠다.


https://blog.devgenius.io/how-to-implement-uuid-in-django-rest-framework-1556467ac7ea

 

How to implement UUID in Django REST framework

Universally unique identifiers, or UUID for short, are also known as GUIDs, i.e., Globally Unique Identifiers.

blog.devgenius.io

A반 발표 때 적용한 팀이 있어서 검색해봤다.

'TIL' 카테고리의 다른 글

TIL 070323  (0) 2023.07.04
TIL 063023  (0) 2023.07.01
TIL 062823  (0) 2023.06.29
TIL 062723  (0) 2023.06.27
TIL 062623  (0) 2023.06.26