Diabetic retinopathy (DR) is a common retinal complication led by diabetes over the years, considered a cause of vision loss. Its timely identification is crucial to prevent blindness, requiring expert humans to analyze digital color fundus images. Hence, it is a time-consuming and expensive process. In this study, we propose a model named Attention-DenseNet for detecting and severity grading of DR. We apply a pre-trained convolutional neural network to extract features and get a hierarchical representation of color fundus images. What is essential for the correct diagnosis of DR is to recognize all the retinal lesions and discriminative regions. However, convolutional neural networks may overlook some tiny lesions of color fundus images. So, we use an attention model to solve this issue, which helps the model focus more on distinctive areas than others. We use APTOS 2019 dataset and fivefold cross-validation to assess the model's performance. The method achieves an overall accuracy of 98.44%, an area under receiver operating characteristic curve of 99.55%, and quadratic weighted kappa of 96.88% for the detection task, and an overall accuracy of 83.69%, an area under receiver operating characteristic curve of 97%, and quadratic weighted kappa of 89.26% for grading task. Our experimental results indicate that the model is superior to recent studies and can be suitable for DR classification in real life, especially for DR detection.